Skip to content

Instantly share code, notes, and snippets.

@saibotsivad
Created June 2, 2014 14:32
Show Gist options
  • Save saibotsivad/53592c3414833daf3c64 to your computer and use it in GitHub Desktop.
Save saibotsivad/53592c3414833daf3c64 to your computer and use it in GitHub Desktop.
Commonly used git commands

If you need to restructure your commit history (squash multiple commits into one, remove commits, etc.) use the command (where N is the number of commits to include in the restructure):

git rebase -i HEAD~N

E.g.,

git rebase -i HEAD~3

will let you change the commit history for the last three commits.


If you need to grab a commit from one branch and apply it to the branch you are currently on, use the command:

git cherry-pick COMMIT_HASH

E.g.

git cherry-pick a2cc80d

will let you grab the local commit a2cc80d and add it to the current branch commit history.


If you need to grab the changes to a specific file from one branch, use the command:

git checkout BRANCH -- FILENAME

This will take the state of the file from that branch, and apply the changes to the current file. It won't make a new commit.

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