Skip to content

Instantly share code, notes, and snippets.

@max-hk
Last active March 5, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-hk/9a4ea2a8c4b0ad85c3b66bf17e4bf15f to your computer and use it in GitHub Desktop.
Save max-hk/9a4ea2a8c4b0ad85c3b66bf17e4bf15f to your computer and use it in GitHub Desktop.
Useful git commands

Useful git commands

A collection of useful git commands

Delete commit

CAUTION: git reset --hard will delete all local changes

Delete commit

git reset --hard HEAD~<no of commit before HEAD>
git reset --hard <commit id>

Push to server

git push origin <branch name> --force

https://stackoverflow.com/a/1338744/11523048
https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git/

Output changed files between commits

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT <commit 1 id>..<commit 2 id> | tar -cf file.tar -T -

https://stackoverflow.com/a/4541846/11523048
https://stackoverflow.com/questions/4541300/export-only-modified-and-added-files-with-folder-structure-in-git/

Show detached heads in a graph

git log --graph --decorate $(git rev-list -g --all)

https://stackoverflow.com/a/16368880/11523048 https://stackoverflow.com/questions/16368605/is-there-a-tool-to-have-git-show-detached-heads-in-a-graph

Globbing on Windows

git am *.txt

in Linux is equivalent to the following in Windows PowerShell

git am $(ls *.txt | % {$_.FullName})

https://superuser.com/a/460651
https://superuser.com/questions/460598/is-there-any-way-to-get-the-windows-cmd-shell-to-expand-wildcard-paths/

@max-hk
Copy link
Author

max-hk commented Jan 30, 2020

List added files

git diff-tree --no-commit-id --name-only -r 786ee8bac --diff-filter=A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment