[英]Git, merging branches git
I can not understand why my merge is updating one commit... it look that it updating commit Add Color, not merging master with coins. 我不明白为什么我的合并会更新一个提交...看起来它正在更新提交添加颜色,而不是将母版与硬币合并。 Sublime doesn't pop out when i try to merge these branches.
当我尝试合并这些分支时,Sublime不会弹出。 Anyone can help me?
有人可以帮助我吗? Moreover when i type git commit i have:
此外,当我输入git commit时,我有:
On branch master Your branch is ahead of 'origin/master' by 2 commits. 在分支母版上您的分支比“原始/母版”提前2次提交。 (use "git push" to publish your local commits) nothing to commit, working tree clean
(使用“ git push”发布您的本地提交)无任何提交,工作树干净
I'm not sure what your question is, but think there's two things going on here you might not fully understand. 我不确定您的问题是什么,但是您可能无法完全理解这里发生的两件事。
First, I don't think git merge master coins
does what you think it does. 首先,我认为
git merge master coins
并没有您认为的那样。
git merge master coins
does not say to merge master
into coins
. git merge master coins
并没有说将master
合并成coins
。 It says to merge master
and coins
into the currently checked out branch. 它说将
master
和 coins
合并到当前签出的分支中。 That's because master coins
is a list of branches to merge into the current branch. 这是因为
master coins
是要合并到当前分支中的分支的列表。 From the docs ... 从文档 ...
[git merge] incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch .
[git merge]将命名提交的更改(自其历史记录与当前分支分开以来的时间) 合并到当前分支中 。
If master
is checked out, then it merges coins into master. 如果检出了
master
,则它将硬币合并到母版中。 If coins
is checked out, then it merges master
into coins
. 如果检出了
coins
,则它将master
合并为coins
。 If something else is checked out you get what's called an "octopus merge" and all three, master
, coins
, and the current branch are merged together into what is probably a big mess. 如果签出了其他内容,您将得到所谓的“章鱼合并”,并且
master
, coins
和当前分支这三个都合并在一起,可能是一团糟。
As it stands, you merged with master
checked out, so git merge master coins
is the same as git merge coins
. 就目前而言,您已与已检出的
master
合并,因此git merge master coins
与git merge coins
相同。 You merged coins
into master
which is, I think, what you wanted, but it could have gone bad. 您将
coins
合并master
,我想这是您想要的,但是它可能变糟了。
So don't use that syntax; 因此,请勿使用该语法。 it can get you in trouble, and it's hard to know what actually happened by looking at the command history.
它会给您带来麻烦,并且通过查看命令历史记录很难知道实际发生了什么。 Instead use
git checkout branch-to-merge-into; git merge branch-to-merge-from
而是使用
git checkout branch-to-merge-into; git merge branch-to-merge-from
git checkout branch-to-merge-into; git merge branch-to-merge-from
. git checkout branch-to-merge-into; git merge branch-to-merge-from
。 So if you want to merge from coins into master, git checkout master; git merge coins
因此,如果要将硬币合并成master,请使用
git checkout master; git merge coins
git checkout master; git merge coins
. git checkout master; git merge coins
。
Next issue is about the fast-forward merge. 下一个问题是关于快进合并。 This is something that Git does when there's no need for a merge, when the branches haven't diverged.
当不需要合并时,分支没有分歧时,Git会执行此操作。 For example, let's say you had this...
例如,假设您有这个...
A - B - C - D - G [master]
\
E - F - H [feature]
Since master
has changes which are not in common with feature
(D and G), it must merge. 由于
master
具有与feature
(D和G)不同的更改,因此必须合并。 So git checkout master; git merge feature
所以
git checkout master; git merge feature
git checkout master; git merge feature
results in a new merge commit. git checkout master; git merge feature
导致新的合并提交。
A - B - C - D - G - I [master]
\ /
E - F - H [feature]
But if there were no new commits on master
, you have this ( master
is pointing at C). 但是,如果
master
上没有新的提交,则可以使用它( master
指向C)。
[master]
A - B - C - E - F - H [feature]
feature
is said to have not diverged from master
. 据说
feature
上没有与master
背道而驰。 There's no need for a merge commit, so Git doesn't bother with one. 不需要合并提交,因此Git不会打扰任何人。 When you do
git checkout master; git merge feature
当你做
git checkout master; git merge feature
git checkout master; git merge feature
it simply moves master
to H. git checkout master; git merge feature
,只需将master
移至H。
[master]
A - B - C - E - F - H [feature]
Git can do this because "branches" are really just labels pointing at a commit. Git之所以可以这样做是因为“分支”实际上只是指向提交的标签。 Now
master
and feature
point at the same commit. 现在,
master
和feature
指向同一提交。
I recommend avoiding fast-forwards while merging feature branches because it loses important archeological information. 我建议在合并要素分支时避免快进,因为它会丢失重要的考古信息。 Someone looking at the repository later cannot tell that E, F, and H were all done as a single branch.
稍后查看存储库的人无法分辨E,F和H都是作为单个分支完成的。
I recommend to always merge feature branches with git merge --no-ff
. 我建议始终将功能分支与
git merge --no-ff
。 This forces Git to make a merge commit and someone trying to figure out your code in the future can know that E, F, and H are all part of a greater whole. 这迫使Git进行合并提交,将来尝试弄清楚您的代码的人可以知道E,F和H都是更大整体的一部分。
A - B - C --------- I [master]
\ /
E - F - H [feature]
The merge commit, I, also gives you a place to describe the branch and add things like a link to the issue/bug/ticket describing what the branch was for. 合并提交I还为您提供了一个描述分支的地方,并添加了指向问题/错误/票证的链接之类的内容,以描述分支的用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.