当 based-off 分支领先于提交时,git 合并如何工作?

How does git merge work when based-off branch is ahead by a commit?

我有两个分支:

开发分支有1个commit,即'init'。 我分支了开发分支的功能分支,所以功能分支也应该有 'init' 的提交。

我将进行更改并将此更改提交到功能分支:

$> git checkout development
$> git commit -am "init"
$> git push
$> git checkout -b feature
$> git commit -am "change"
$> git push

现在另一个开发人员将向开发分支添加更改:

$> git checkout development
$> git commit -am "another change"
$> git push

假设我想将功能分支合并到开发分支中,现在开发分支因为其他开发人员所做的而领先于一个更改,这会不会导致任何问题?

$> git checkout development
$> git merge feature

如果我想继续在feature分支上做,由于还缺少一些东西,feature还没有完成,我已经将feature分支合并到development分支中了。我是否需要将开发分支合并到功能分支中,以便功能分支不丢失任何东西?还是这根本不需要继续我的工作?

Say that I would like to merge the feature branch into the development branch, will this cause any problems now that the development branch is ahead by one change because of what the other developer did?

Git 不关心,但合并的结果将未经测试。您需要测试合并的结果。通常这是通过自动化测试完成的。

最好更新功能分支(见下文),测试功能分支,然后合并。这就是 Github 拉取请求和 Gitlab 合并请求所做的。

If I would like to continue working on the feature branch, since something is still missing, the feature is still incomplete and I already merged feature branch into the development branch.

您应该合并功能分支,直到它完成。功能分支用于一个功能。工作完成后 . If you want another feature, open a new feature branch. This is the Feature Branch Workflow.

如果你不小心合并了,而且合并还没有被推送,undo the merge. If it has been pushed, and it works, but it's just incomplete, open a new branch to continue your work. If it has been pushed and it introduces bugs, undo the merge and git push --force-with-lease 去掉坏的合并。

Do I need to merge the development branch into the feature branch so that the feature branch is not missing anything? Or is this not necessary at all to continue my work?

是的,您应该通过使用 git merge development 合并这些更改或使用 git rebase development 在开发之上重写您的工作,使您的分支与开发保持同步。我推荐后者,但它确实需要对 Git.

有扎实的理解

同样,这不是绝对必要的,但定期更新和处理来自其他开发人员的小块更改可以避免最后出现大惊喜。