From 119af213d2686a638f862473d61d7401efbeeea0 Mon Sep 17 00:00:00 2001 From: "E.F." Date: Mon, 27 Oct 2025 21:05:02 +0100 Subject: [PATCH 1/2] Added two git tricks concerning add and amend --- .../my_favorite_neat_little_git_trick_demo.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/01_version_control/my_favorite_neat_little_git_trick_demo.md b/01_version_control/my_favorite_neat_little_git_trick_demo.md index ad4521c0..e0639265 100644 --- a/01_version_control/my_favorite_neat_little_git_trick_demo.md +++ b/01_version_control/my_favorite_neat_little_git_trick_demo.md @@ -18,6 +18,19 @@ - If you rebased/merged and messed up your history, use `git reflog` to go back to a previous state - If you only need one file from another commit or branch, use `git checkout -- ` - Use [Git LFS](https://git-lfs.com/) for big files >10 MB or for non-diffable binaries (e.g., images, media, archives, shared libraries). +- 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 +- A very nice alias for editing any earlier commit, without having to manually rebase: + + ``` + [alias] + amend = "!f() { \ + COMMIT=$(git rev-parse --short \"$1\") && \ + git commit --fixup \"$COMMIT\" && \ + GIT_SEQUENCE_EDITOR=true git rebase --autosquash --autostash --interactive "$COMMIT^"; \ + }; f" + ``` + + Usage: e.g. `git add -p ...` and then `git amend HEAD~5`. This would add the staged changes to the fifth last commit. ## Tricks from Winter Term 2024/25 From 30f94730a418ebb3cd00520ef3ccb5ffa76a923b Mon Sep 17 00:00:00 2001 From: Benjamin Uekermann Date: Wed, 19 Nov 2025 16:06:23 +0100 Subject: [PATCH 2/2] Fix md formatting Added usage example for git commit --fixup trick. --- 01_version_control/my_favorite_neat_little_git_trick_demo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_version_control/my_favorite_neat_little_git_trick_demo.md b/01_version_control/my_favorite_neat_little_git_trick_demo.md index e0639265..db2f4588 100644 --- a/01_version_control/my_favorite_neat_little_git_trick_demo.md +++ b/01_version_control/my_favorite_neat_little_git_trick_demo.md @@ -29,7 +29,7 @@ GIT_SEQUENCE_EDITOR=true git rebase --autosquash --autostash --interactive "$COMMIT^"; \ }; f" ``` - + Usage: e.g. `git add -p ...` and then `git amend HEAD~5`. This would add the staged changes to the fifth last commit. ## Tricks from Winter Term 2024/25