git merge origin/branch与本地合并分支
当我将 origin/branchX
合并到 branchY
和将 branchX
合并到 branchY
之间时,有什么区别??
What is the different between when I merge the origin/branchX
into branchY
and merge branchX
into branchY
?
origin/branchX
是一个远程跟踪分支,每次您执行时,都会通过远程存储库中的更改进行更新.git fetch
.另一方面, branchX
是此分支的本地版本. branchX
可能与 origin/branchX
不同步,而 origin/branchX
可能与远程存储库中的实际内容不同步.
origin/branchX
is a remote tracking branch, and gets updated with changes from the remote repository every time you do a git fetch
. On the other hand, branchX
is your local version of this branch. branchX
may be out of sync with origin/branchX
which in turn may be out of sync with what is actually on the remote repository.
因此,合并中的差异将取决于 branchX
的各种化身中的差异.如果要将最新的 branchX
合并到您的 branchY
中,则应执行以下操作:
Hence the difference in doing a merge will depend on the differences in the various incarnates of branchX
. If you want to merge the very latest branchX
into your branchY
then you should do the following:
git fetch origin # update remote tracking branchX
git checkout branchY # switch to branchY
git merge origin/branchX # merge
如果您还希望在此过程中更新本地 branchX
,则可以执行以下操作:
If you want to also update your local branchX
in the process, you could do this:
git checkout branchX
git pull origin branchX
git checkout branchY
git merge branchX
但是,您可能需要将 branchX
的本地副本合并到 branchY
中,而无需与远程分支同步.例如,如果遥控器上的 branchX
中进行了新更改,而您又不想将其引入 branchY
中,则这将是一个典型的用例.在这种情况下,您将像这样执行合并:
However, you might have the need to merge your local copy of branchX
into branchY
without synching either branch with the remote. This would be a typical use case if, for example, new changes came into branchX
on the remote and you did not want to bring them into branchY
just yet. In this case you would perform the merge like this:
git checkout branchY
git merge branchX