Different commits between master and remote origin

git log –left-right –graph –cherry-pick –oneline master…remotes/origin/master

Combine two commits into one

git rebase -i

Difference between (^) and (~)

ref~ is shorthand for ref~1 and means the commit’s first parent. ref~2 means the commit’s first parent’s first parent. ref~3 means the commit’s first parent’s first parent’s first parent. And so on.

ref^ is shorthand for ref^1 and means the commit’s first parent. But where the two differ is that ref^2 means the commit’s second parent (remember, commits can have two parents when they are a merge).

The ^ and ~ operators can be combined.


Push to local branch to remote master branch

$ git push origin develop:master

or, more generally

$ git push <remote> <local branch name>:<remote branch to push into>

Delete remote branch 

git branch -rD reference/branch

Ex: git branch -rD origin/0.2

Overwrite branch master from branch xxx:

git checkout master

git reset –hard xxx

Overwrite the file with that on the other branch

git checkout toBranch

git checkout fromBranch filename

Useful notation:



Apply a specific commit from branch A to branch B

git checkout branchB

git cherry-pick SHA of branchA

Reset commit message

git reset –soft HEAD^ or

git commit –amend -m ‘message’

Tag a branch

git checkout master

git tag v0.1    #tagging v0.1 to master branch

git tag    #Show tags in this branch

git push origin –tag    #Push tag to remotes

git push origin v0.1    #Same as above

Rename branch

git branch -m old-branch new-branch

git branch -m new-branch    #If already on old-branch

Checkout a branch

git checkout -b newBranch oldBranch


git reset HEAD~1

Create a branch out of a remote branch 

git branch new-branch master # 由 master 產生新的 branch(new-branch)

Get changes from local branch (master)

git pull . master

git remote add roy-csi ssh://
git fetch roy-csi
git branch local-branch roy-csi

git checkout -b test –track alien_userman/feature/user_management
git remote show alien_userman
git push alien_userman test:feature/user_management
(git push dest_repo from_branch:to_branch)

Overwrite local branch with remote branch
git fetch –all
git reset –hard repo/branch

Delete remote branch
git push repo :newfeature

Move 2 commits onto another branch
e.g. Move 2 commits from externalID_device onto master, but currently resides on externalID_device. ebfd2eea8890 is from_commit, externalID_device is to_commit.
git rebase –onto master ebfd2eea8890 externalID_device

Create patch
git format-patch -n

Apply patch
git apply –ignore-space-change –ignore-whitespace diff.patch

Git revert
git revert <commit>

Git rebase (Overwrite by upstream filename)
Git checkout –ours filename

本篇發表於 Git。將永久鏈結加入書籤。


在下方填入你的資料或按右方圖示以社群網站登入: Logo

您的留言將使用 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )


您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s