Last active
December 27, 2017 14:12
-
-
Save ouyi/ffb64f2018cffa31ce381a3814c52896 to your computer and use it in GitHub Desktop.
Frequently used Git commands
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
# Update commit comments before the push | |
git commit -m "Fix an issue" | |
git commit -m "Fix an important issue" --amend | |
# Throw away all changes on local master and to have it exactly the same as origin/master: | |
git checkout master | |
git reset --hard origin/master | |
# Force origin/master to be the same as local master (dangerous!!!): | |
git push -f origin master:master | |
# Clean up already merged local branches | |
git branch --merged | grep -v master | while read b; do echo $b; git branch -d "$b" ; done | |
# Get hash code of the empty tree | |
# Useful when a "complete" patch file is required, e.g., for a completely new project on the review board | |
git hash-object -t tree --stdin < /dev/null | |
# 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
# git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 <another commit hash> | |
# File-level overview about the changes | |
git diff --summary hash1 hash2 | |
git diff --name-status hash1 hash2 | |
# Export Git project without history | |
git archive --format zip --output /tmp/project_awesome.zip hash1 | |
# Show all changes a branch would bring onto the master (a diff in the pull request style) | |
git diff origin/master...origin/feature_awesome | |
# Commands for producing a Git patch of a merge commit and using the patch to revert the commit | |
git diff origin/master...origin/feature_awesome > changes.patch | |
# Use the patch for a rollback | |
git apply -R changes.patch | |
# See https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.html | |
# A merge commit can not be reverted "completely" -- only the content changes can be reverted, | |
# not the merge history, i.e., the fact that a merge commit has two paraents can not be reverted. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment