Git: quick tips
Nov 09, 2015
devtip , git
Handy commands
- Change a commit message (only if it has not been pushed to upstream)
$ git commit --amend -m "<NEW_COMMIT_MESSAGE>"
$ git cherry -v <other_branch> + 2deea696b5040f3269130aa5cadd5a8c123550b3 first commit + cc08a232c5a06f409f6e1f8fc8915e27a1485a22 second commit - 24831ddb1788217ff24da9e85038dadf7045db7e different commit on the other_branch
$ git merge --squash branch-x
$ git pull --rebase
$ git rebase -i HEAD~N
$ git push origin branch-x-v2:branch-x-v2-sumit Total 0 (delta 0), reused 0 (delta 0) To ssh://git.server.com/pkg/MyPackage * [new branch] branch-x-v2 -> branch-x-v2-sumit
$ git push origin origin/branch-x-v2:refs/heads/branch-x-v2-old :branch-x-v2 Total 0 (delta 0), reused 0 (delta 0) To ssh://git.server.com/pkg/MyPackage - [deleted] branch-x-v1 * [new branch] origin/branch-x-v2 -> branch-x-v2-old
Git Stash
- Push uncommitted changes to stash
$ git stash save "message"
$ git stash list stash@{0}: On branch-x: foo bar 1 stash@{1}: On branch-x: foo bar
$ git stash show -p stash@{0} diff --git a/build.xml b/build.xml index 6ce3fdf..15669ac 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,6 @@ .... ....
$ git stash pop stash@{1} On branch branch-x Your branch is up-to-date with 'origin/branch-x'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: build.xml Untracked files: (use "git add <file>..." to include in what will be committed) .... no changes added to commit (use "git add" and/or "git commit -a") Dropped stash@{1} (caceeb6392c7a40dd8325f3a2fdf038342e629cf)
$ git stash apply stash@{0} On branch branch-x Your branch is up-to-date with 'origin/branch-x'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: build.xml Untracked files: (use "git add <file>..." to include in what will be committed) ..... no changes added to commit (use "git add" and/or "git commit -a")
$ git stash branch my-branch stash@{0}
$ git stash drop stash@{0} Dropped stash@{0} (f697125c22addf9cf31e8ac36b384857110fec0e)
$ git stash clear
Using vimdiff for resolving merge conflicts
- Run mergetool on conflict
git mergetool
$ git config merge.tool vimdiff $ git config merge.conflictstyle diff3 $ git config mergetool.prompt false
# get diff from REMOTE – file we are merging into your branch :diffget RE :diffg RE # get diff from BASE - common ancestor, how file looked before both changes :diffget BA :diffg BA # get diff from LOCAL – this is file from the current branch :diffget LO :diffg LO