Add some more advanced tips
This commit is contained in:
17
snippets/commit-template.md
Normal file
17
snippets/commit-template.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
title: Add a commit message template
|
||||
tags: repository,configuration,advanced
|
||||
---
|
||||
|
||||
Sets up a commit message template for the current repository.
|
||||
|
||||
- Use `git config commit.template <file>` to specify `<file>` as the commit message template for the current repository.
|
||||
|
||||
```sh
|
||||
git config commit.template <file>
|
||||
```
|
||||
|
||||
```sh
|
||||
git config commit.template "commit-template"
|
||||
# Sets "commit-template" as the commit message template
|
||||
```
|
||||
20
snippets/find-lost-files.md
Normal file
20
snippets/find-lost-files.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Find lost files
|
||||
tags: repository,advanced
|
||||
---
|
||||
|
||||
Prints a list of lost files and commits.
|
||||
|
||||
- Use `git fsck --lost-found` to print a list of all dangling objects.
|
||||
- All appropriate files will be extracted into the `.git/lost-found` directory.
|
||||
|
||||
```sh
|
||||
git fsck --lost-found
|
||||
```
|
||||
|
||||
```sh
|
||||
git fsck --lost-found
|
||||
# dangling commit 3050fc0de
|
||||
# dangling blob 807e3fa41
|
||||
# dangling commit 59ff8481d
|
||||
```
|
||||
17
snippets/line-endings.md
Normal file
17
snippets/line-endings.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
title: Configure line endings
|
||||
tags: repository,configuration,intermediate
|
||||
---
|
||||
|
||||
Configures the line endings for a repository.
|
||||
|
||||
- Use `git config core.eol [lf | crlf]` to configure the line endings.
|
||||
- `lf` is the UNIX line ending (`\n`), whereas `crlf` is the DOS line ending (`\r\n`).
|
||||
|
||||
```sh
|
||||
git config core.eol [lf | crlf]
|
||||
```
|
||||
|
||||
```sh
|
||||
git config core.eol lf # Configured to use UNIX line endings
|
||||
```
|
||||
27
snippets/move-commits-to-branch.md
Normal file
27
snippets/move-commits-to-branch.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
title: Move commits from master to a new branch
|
||||
tags: branch,repository,intermediate
|
||||
---
|
||||
|
||||
Moves local commits from the `master` branch to a new branch.
|
||||
|
||||
- Use `git branch <branch>` to create a new branch at the tip of the current `master`.
|
||||
- Use `git reset HEAD~<n> --hard` to rewind back `<n>` commits and discard changes.
|
||||
- Use `git checkout <branch>` to switch to the new branch.
|
||||
- Only works if the changes have only been committed locally and not pushed to the remote.
|
||||
|
||||
```sh
|
||||
git branch <branch>
|
||||
git reset HEAD~<n> --hard
|
||||
git checkout <branch>
|
||||
```
|
||||
|
||||
```sh
|
||||
git checkout master
|
||||
git add .
|
||||
git commit -m "Fix network bug"
|
||||
git branch patch-1
|
||||
# `patch-1` branch is created containing the commit "Fix network bug"
|
||||
git reset HEAD~1 --hard # Remove the commit from `master`
|
||||
git checkout patch-1
|
||||
```
|
||||
20
snippets/sort-branches-by-date.md
Normal file
20
snippets/sort-branches-by-date.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: View branches sorted by date
|
||||
tags: repository,branch,intermediate
|
||||
---
|
||||
|
||||
Prints a list of all local branches sorted by date.
|
||||
|
||||
- Use `git branch --sort=-committerdate` to display a list of all local branches and sort them based on the date of their last commit.
|
||||
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
|
||||
|
||||
```sh
|
||||
git branch --sort=-committerdate
|
||||
```
|
||||
|
||||
```sh
|
||||
git branch --sort=-committerdate
|
||||
# master
|
||||
# patch-1
|
||||
# patch-2
|
||||
```
|
||||
Reference in New Issue
Block a user