git rebase without using a branch

Suppose I am not using branch (I am working on a local master branch, with origin to be master branch on remote server). Wondering what is the function of the command? My confusion is sometimes I see people using this command to merge local changes (with changes on master remote server branch) successfully without using branch, but I could be wrong but I think rebase only works when you are working on a branch (master) and merge with some other branch?

git rebase -i origin/master 

origin/master is a branch just like master . It is basically tracks whatever contents are on the remote master.

When you run git fetch from master it will fetch all commits from your remote master and put it onto origin/master . If you then run git rebase -i origin/master , this happens:

  • all your commits that were not on origin/master are temporarily put away
  • your master is updated with whatever is on origin/master
  • your commits are replayed on top of your updated master
  • So, if you first manually fetch and then rebase , thats basically manually doing what git pull --rebase would do.

    As an aside, you can also rebase onto your own branch, for example: git rebase HEAD~2 . This will let you re-order (or otherwise edit) the commits on your current branch.

    链接地址: http://www.djcxy.com/p/45094.html

    上一篇: Git rebase一次又一次回到同一个地方

    下一篇: 没有使用分支的git rebase