Last active
April 5, 2024 09:40
-
-
Save Wooder/ac35e0d716ab9122ca4c3568943e4715 to your computer and use it in GitHub Desktop.
useful-git-commands collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#H1 Useful GIT commands | |
#H2 Which Git Branches contain the given commit | |
#H3 local | |
git branch --contains your_commit_hash | |
#H3 remote | |
git branch -a --contains your_commit_hash | |
#H2 Revert a merge commit that was already pushed | |
git revert -m 1 <commit-hash> | |
git commit -m "revert the last merge commit which was wrong." | |
git push | |
#H2 Revert a local merge that was not commited yet | |
git merge --abort | |
#H2 Find and restore a stash that was deleted on source tree | |
git fsck 2> /dev/null | awk '/commit/{print $3}' | git show --stdin --merges --grep 'Somestring that identiefies your deleted stash' | |
#H3 | |
then take the commit hash of the stash you found and apply statsh to restore it | |
git stash apply 9608bca44613c4537be4ebacf4057de5a5c3db2e | |
#H2 pretty printed git log | |
git config --global alias.smartlog "log --graph --pretty=format:'commit: %C(bold red)%h%Creset %C(red)<%H>%Creset %C(bold magenta)%d %Creset%ndate: %C(bold yellow)%cd %Creset%C(yellow)%cr%Creset%nauthor: %C(bold blue)%an%Creset %C(blue)<%ae>%Creset%n%C(cyan)%s%n%Creset'" | |
git config --global alias.sl '!git smartlog' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment