You can review the differences with a:
(您可以通过以下方式查看差异 :)
git log HEAD..origin/master
before pulling it (fetch + merge) (see also "How do you get git to always pull from a specific branch?" )
(在拉它之前(fetch + merge)(另请参阅“如何让git始终从特定分支中拉出来?” ))
When you have a message like:
(如果您有以下消息:)
"Your branch and 'origin/master' have diverged, # and have 1 and 1 different commit(s) each, respectively."
(“你的分支和'origin / master'分歧,#并分别有1个和1个不同的提交。”)
, check if you need to update origin
.
(,检查是否需要更新origin
。)
If origin
is up-to-date, then some commits have been pushed to origin
from another repo while you made your own commits locally. (如果origin
是最新的,那么当您在本地进行自己的提交时,一些提交已被推送到另一个repo的origin
。)
... o ---- o ---- A ---- B origin/master (upstream work)
C master (your work)
You based commit C on commit A because that was the latest work you had fetched from upstream at the time.
(您基于提交A提交C,因为这是您当时从上游获取的最新工作。)
However, before you tried to push back to origin, someone else pushed commit B.
(但是,在您尝试推回原点之前,其他人推送了提交B.)
Development history has diverged into separate paths.
(发展历史已分化为不同的路径。)
You can then merge or rebase.
(然后,您可以合并或变基。)
See Pro Git: Git Branching - Rebasing for details. (有关详细信息,请参阅Pro Git:Git Branching - Rebasing 。)
Merge
(合并)
Use the git merge command:
(使用git merge命令:)
$ git merge origin/master
This tells Git to integrate the changes from origin/master
into your work and create a merge commit.
(这告诉Git将来自origin/master
的更改集成到您的工作中并创建合并提交。)
The graph of history now looks like this:
(历史图现在看起来像这样:)
... o ---- o ---- A ---- B origin/master (upstream work)
C ---- M master (your work)
The new merge, commit M, has two parents, each representing one path of development that led to the content stored in that commit.
(新的merge,commit M,有两个父节点,每个父节点代表一条开发路径,导致存储在该提交中的内容。)
Note that the history behind M is now non-linear.
(请注意,M背后的历史现在是非线性的。)
Rebase
(变基)
Use the git rebase command:
(使用git rebase命令:)
$ git rebase origin/master
This tells Git to replay commit C (your work) as if you had based it on commit B instead of A.
(这告诉Git重放提交C(你的工作),好像你是基于提交B而不是A.)
CVS and Subversion users routinely rebase their local changes on top of upstream work when they update before commit.
(CVS和Subversion用户在提交之前更新时会定期在上游工作之上重新定义其本地更改。)
Git just adds explicit separation between the commit and rebase steps.
(Git只是在commit和rebase步骤之间添加了明确的分离。)
The graph of history now looks like this:
(历史图现在看起来像这样:)
... o ---- o ---- A ---- B origin/master (upstream work)
C' master (your work)
Commit C' is a new commit created by the git rebase command.
(Commit C'是由git rebase命令创建的新提交。)
It is different from C in two ways:
(它在两个方面与C不同:)
- It has a different history: B instead of A.
(它有不同的历史:B而不是A.)
- Its content accounts for changes in both B and C;
(其内容考虑了B和C的变化;)
it is the same as M from the merge example. (它与合并示例中的M相同。)
Note that the history behind C' is still linear.
(请注意,C'背后的历史仍然是线性的。)
We have chosen (for now) to allow only linear history in cmake.org/cmake.git
.
(我们选择(目前)只允许在cmake.org/cmake.git
使用线性历史记录。)
This approach preserves the CVS-based workflow used previously and may ease the transition.
(这种方法保留了之前使用的基于CVS的工作流程,可以简化过渡。)
An attempt to push C' into our repository will work (assuming you have permissions and no one has pushed while you were rebasing).
(尝试将C'推入我们的存储库将起作用(假设您有权限,并且在您重新定位时没有人推送)。)
The git pull command provides a shorthand way to fetch from origin and rebase local work on it:
(git pull命令提供了一种从源获取并在其上重新定义本地工作的简写方法:)
$ git pull --rebase
This combines the above fetch and rebase steps into one command.
(这将上面的fetch和rebase步骤合并为一个命令。)