Git Solutions Collection
Amend a commit
git commit --amend
Git pull till a particular commit
git fetch remote <branch_name>
git merge <commit_hash>
Your branch and ‘origin/master’ have diverged
git fetch origin
git reset --hard origin/master
Remove all unreachable objects
git reflog expire --expire-unreachable=now --all
git gc --prune=now
Remove tracked files in .gitignore
Remove a file
git rm --cached <file>
Remove a folder recursively
git rm -r --cached <folder>
Recover a dropped stash entry
If the following code is executed accidentally
git stash pop
git checkout -- .
First, use gitk
to find the corresponding hash value
gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
Then, run git stash
to apply the stash entry
git stash apply <stash_hash>