[Git] Common Usage

来源:互联网 发布:安畅网络水军平台 编辑:程序博客网 时间:2024/04/30 13:59

rebase

Before:
“This branch is 3 commits behind octantis:master.”

git fetch upstream
git rebase upstream/master
git push origin master

After:
“This branch is even with octantis:master.”

Screenshot:
git commands

target status

Reference: Syncing a fork

Why rebasing?

Often, you’ll do this to make sure your commits apply cleanly on a remote branch – perhaps in a project to which you’re trying to contribute but that you don’t maintain. In this case, you’d do your work in a branch and then rebase your work onto origin/master when you were ready to submit your patches to the main project. That way, the maintainer doesn’t have to do any integration work – just a fast-forward or a clean apply.

Note that the snapshot pointed to by the final commit you end up with, whether it’s the last of the rebased commits for a rebase or the final merge commit after a merge, is the same snapshot – it’s only the history that is different. Rebasing replays changes from one line of work onto another in the order they were introduced, whereas merging takes the endpoints and merges them together.

References

(1) https://git-scm.com/about

0 0