合并分支:为什么gitmerge-no-ff没有合并所有分支


  • 第一次使用git时遇到合并问题。工作流程如下:

  • 在gitlab上创建存储库,每个成员本地链接

  • 向master分支添加了两个文本文件-recipe_book.txt和ingredients.txt
  • 编辑了这两个文件,并添加、提交和推送了它们
  • 从大师意大利面和披萨意大利面中创建了两个分支
  • 在pizzaparta分支中,这两个文件都被重写(不仅仅是轻微修改),添加了committed和push
  • 在素食分支中,这两个文件都被重写(不仅仅是轻微修改)、添加提交和推送
  • 在master上,master和比萨饼意大利面被合并,这导致了一个快速的合并(如下所示)-已恢复为提交合并前-尝试不进行快进合并,但只有披萨意大利面中文件的部分内容被添加到master中的文件内容中

此任务的目标是在三个不同分支中的两个文件(文件必须保留相同的名称,但内容必须完全不同),最后必须合并所有分支,以便主分支中的文件包含最初在三个分支中的每个分支中的内容。

使用的命令摘要(文件编辑由每个参与者手动和本地完成):

git add ingredients.txt
git commit -m "adding blank file ingredients.txt"
git add recipe_book.txt
git commit -m "adding blank file recipe_book.txt"
git push -u origin master
git add ingredients.txt
git commit -m "updating file ingredients.txt with content"
git add recipe_book.txt
git commit -m "updating file recipe_book.txt with content"
git push -u origin master
git branch vegetarian
git push origin vegetarian
git branch pizza-pasta
git push origin pizza-pasta
git checkout vegetarian
git add ingredients.txt
git commit -m "updating file ingredients.txt with completely new content"
git add recipe_book.txt
git commit -m "updating file recipe_book.txt with completely new content"
git push -u origin vegetarian
git checkout pizza-pasta
git add ingredients.txt
git commit -m "updating file ingredients.txt with completely new content"
git add recipe_book.txt
git commit -m "updating file recipe_book.txt with completely new content"
git push -u origin pizza-pasta
git checkout master
git merge master pizza-pasta \ here i made the fast-forward merge mistake
git reset --hard fe6fff
git reset --soft HEAD@{1}
git commit -m "reverting to pre-merge"
git push -u origin master
git merge --no-ff master pizza-pasta \ here i made the merge with no fast-forward 

如果素食分支通过删除/完全更改所有行,然后添加回素食行来编辑recipe_book.txt,那么合并回master将看起来像是"覆盖"(但实际上只是一个快进合并)。

$ git init
Initialized empty Git repository in /code/test-git/.git/
$ touch recipe_book.txt
$ echo steak > recipe_book.txt
$ cat recipe_book.txt
steak
$ git add recipe_book.txt
$ git commit -m "steak"
[master (root-commit) 25b1f57] steak
1 file changed, 1 insertion(+)
create mode 100644 recipe_book.txt
$ git checkout -b veg
Switched to a new branch 'veg'
$ echo tofu > recipe_book.txt
$ cat recipe_book.txt
tofu
$ git commit -am "tofu"
[veg e765cb4] tofu
1 file changed, 1 insertion(+), 1 deletion(-)
$ git checkout master
Switched to branch 'master'
$ cat recipe_book.txt
steak
$ git merge veg
Updating 25b1f57..e765cb4
Fast-forward
recipe_book.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ cat recipe_book.txt
tofu

最新更新