Skip to content

Commit e9ad1a8

Browse files
feegeeruekerman
andauthored
Add interactive add and amend to git tricks
* Added two git tricks concerning add and amend * Fix md formatting Added usage example for git commit --fixup trick. --------- Co-authored-by: Benjamin Uekermann <benjamin.uekermann@gmail.com>
1 parent 89fc03e commit e9ad1a8

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

01_version_control/my_favorite_neat_little_git_trick_demo.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
- If you rebased/merged and messed up your history, use `git reflog` to go back to a previous state
1919
- If you only need one file from another commit or branch, use `git checkout <branch_or_sha> -- <path>`
2020
- Use [Git LFS](https://git-lfs.com/) for big files >10 MB or for non-diffable binaries (e.g., images, media, archives, shared libraries).
21+
- Prefer `git add -p` over `git add [FILE]`. This allows you to specify what you want to add to a commit in a more fine-grained manner
22+
- A very nice alias for editing any earlier commit, without having to manually rebase:
23+
24+
```
25+
[alias]
26+
amend = "!f() { \
27+
COMMIT=$(git rev-parse --short \"$1\") && \
28+
git commit --fixup \"$COMMIT\" && \
29+
GIT_SEQUENCE_EDITOR=true git rebase --autosquash --autostash --interactive "$COMMIT^"; \
30+
}; f"
31+
```
32+
33+
Usage: e.g. `git add -p ...` and then `git amend HEAD~5`. This would add the staged changes to the fifth last commit.
2134
2235
## Tricks from Winter Term 2024/25
2336

0 commit comments

Comments
 (0)