[英]Changes in branch after merge in git
I have two branches, foo
and bar
under master
in a project that I'm managing with git. 在我用git管理的项目中,我在
master
下有两个分支, foo
和bar
。 Let's suppose I work under foo
and after being done with it, I merge the changes with master
. 假设我在
foo
下工作,并在完成后将更改与master
合并。 Then I go to bar
and repeat the process. 然后,我去
bar
重复该过程。 But then someone tells me there's something I have to change on foo
, so my first idea was to repeat again, but then I lose all the work done under bar
branch. 但是后来有人告诉我,我必须在
foo
上进行一些更改,所以我的第一个想法是重复一遍,但是后来我失去了在bar
分支下完成的所有工作。 How do I achieve my purpose of coming back to a branch and then when I merge with master
I don't override the changes made under bar
我如何实现回到分支的目的,然后在与
master
合并时不覆盖在bar
下所做的更改
I tried creating a new branch for those new changes but if this is the approach, I find the branches a bit useless. 我尝试为这些新更改创建一个新分支,但是如果采用这种方法,我会发现这些分支没有用。 But I think git is smart enough to do what I want.
但是我认为git很聪明,可以做我想要的事情。
Answering with a series of diagrams: 回答一系列图表:
-- -
create foo
and bar
off master
after commit C: 在提交C之后创建
foo
并bar
master
:
foo
/
master A ---- B ---- C
\
bar
work on foo
and merge into master
: ( git checkout master && git merge foo
) 在
foo
工作并合并到master
:( git checkout master && git merge foo
)
foo D ---- E ---- F
/ \ (merge-commit)
master A ---- B ---- C --------------- G
\
bar
meanwhile, bar
progressed independently.. 同时,
bar
独立发展。
foo D ---- E ---- F
/ \
master A ---- B ---- C --------------- G
\
bar D' ---- E' ----- F'
you now wish to update bar
with changes to master
( git pull origin master
) 您现在希望通过更改
master
来更新bar
( git pull origin master
)
foo D ---- E ----------- F
/ \
master A ---- B ---- C ---------------------- G
\ \
bar D' ---- E' ----- F' ---- G' (another merge-commit)
another change commited on foo
对
foo
提交的另一个更改
foo D ---- E ----------- F ---- H
/ \
master A ---- B ---- C ---------------------- G
\ \
bar D' ---- E' ----- F' ---- G'
then, to sync bar
with new foo
( git checkout bar && git pull origin foo
) 然后,将
bar
与新的foo
同步( git checkout bar && git pull origin foo
)
foo D ---- E ----------- F ---- H
/ \ \
master A ---- B ---- C ---------------------- G \
\ \ \
bar D' ---- E' ----- F' ---- G'---- H' (another merge-commit)
then merge bar
into master
(with master
as active branch, git merge bar
) 然后将
bar
合并到master
(将master
作为活动分支, git merge bar
)
foo D ---- E ----------- F ---- H
/ \ \
master A ---- B ---- C ---------------------- G -----}-------- I (latest merge-commit)
\ \ \ /
bar D' ---- E' ----- F' ---- G'---- H' ---
Then I go to bar and repeat the process
然后我去酒吧重复一下过程
Why don't you merge master or foo in bar? 为什么不合并bar中的master或foo? That's unclear to me.
我不清楚。
But then someone tells me there's something I have to change on foo, so my first idea was to repeat again, but then I lose all the work done under bar branch.
但是后来有人告诉我,我必须在foo上进行一些更改,所以我的第一个想法是重复一遍,但是后来我失去了在bar分支下完成的所有工作。
What do you mean with repeat? 重复是什么意思? Commit you last changes and checkout the other branch.
提交最后的更改并签出另一个分支。
Also if you made changes that you won't commit you can use git stash for storing the changes temporary. 另外,如果您进行了不提交的更改,则可以使用git stash临时存储更改。
Please specify your question for more detailed help. 请指定您的问题以获得更详细的帮助。
If your foo
and bar
branch is not yet deleted, you can rebase 如果您的
foo
and bar
分支尚未删除,则可以重新设置基准
git checkout master
git pull
git checkout foo
git rebase master
git checkout bar
git rebase master
But ideally, if your foo
and bar
branch is a feature/issue, you should only merge them to master when it's done. 但理想情况下,如果您的
foo
和bar
分支是一个功能/问题,则仅应在完成后将它们合并到master。 If it's too big, break it down to smaller branches (nester or flat). 如果太大,则将其分解为较小的分支(蝶形或扁平形)。
I don't override the changes made under bar
我不会覆盖在bar下所做的更改
this depends on your changes and why care, you merge bar
branch to master
anyway. 这取决于您的更改以及为什么要关心,无论如何您都要合并
bar
分支以master
。 It's none of bar
business if the work he have done is modify because that feature/fix is done (that's why you merge it). 如果他所做的工作因功能/修复完成而被修改(这就是您将其合并的原因)而被修改,这与
bar
业务无关。 Actually, when you finished a feature/fix branch and merge it master, ideally you delete it cause it's done. 实际上,当您完成了一个功能部件/修订版分支并合并了它的母版后,理想情况下您将其删除,因为它已经完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.