第一次使用git并遇到合并问题。工作流程如下:
在gitlab上创建了存储库,每个成员都在本地链接
此任务的目标是三个不同分支中的两个文件(文件必须保留相同的名称,但内容必须完全不同),最后必须合并所有分支,以便主分支中的文件包含最初是在三个分支中的每个分支。
使用的命令摘要(文件的编辑由每个参与者手动和本地完成):
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
答案 0 :(得分:0)
如果素食分支通过删除/完全更改所有行来编辑recipe_book.txt
,然后添加回素食行,那么合并回主人将看起来像"覆盖" (但实际上只是一个fast-forward merge)。
$ 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