git .gitignore 中的合并冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12160676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge conflict in .gitignore
提问by Nyxynyx
I have 2 branches, master
and newfeature
. When I want to merge newfeature
into master
, I used:
我有 2 个分支,master
并且newfeature
. 当我想合并newfeature
到 时master
,我使用了:
git checkout master
git merge newfeature
I get the error:
我收到错误:
Auto-merging .gitignore
CONFLICT (content): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
I opened up .gitignore
and it looks like a mess now with the last part of the file looking like
我打开了.gitignore
,现在看起来像一团糟,文件的最后一部分看起来像
<<<<<<< HEAD
public/img/ignore
=======
public/img/profiles
public/blog
public/recommendation
>>>>>>> newfeature
What happened, and how should this be fixed so that I can merge the branch into master
?
发生了什么,应该如何解决这个问题,以便我可以将分支合并到master
?
回答by D-Rock
You edited the .gitignore in both branches. Now, git is unsure of which lines in each copy are the correct ones so it is asking you to resolve them.
您在两个分支中都编辑了 .gitignore。现在,git 不确定每个副本中的哪些行是正确的,因此它要求您解决它们。
The lines:
线路:
<<<<<<< HEAD
public/img/ignore
=======
Are what appears in the copy of the file in master.
是主文件副本中出现的内容。
And
和
=======
public/img/profiles
public/blog
public/recommendation
>>>>>>> newfeature
in the branch newfeature
在分支新功能中
You should just have to edit the file as you would like it to appear finally. Then...
您应该只需要编辑文件,因为您希望它最终出现。然后...
git add .gitignore
git commit
回答by ?ukasz Strza?kowski
Simply edit .gitignore
file to resolve conflict:
只需编辑.gitignore
文件即可解决冲突:
Before
前
<<<<<<< HEAD
public/img/ignore
=======
public/img/profiles
public/blog
public/recommendation
>>>>>>> newfeature
After
后
public/img/ignore
public/img/profiles
public/blog
public/recommendation
Then:
然后:
git add .gitignore
git add .gitignore
git commit
git commit
Autogenerated commit message should apear, accept it (save & close) and it's done.
自动生成的提交消息应该出现,接受它(保存并关闭)并完成。
回答by eis
What happened is that there was a merge conflict: two branches changed the file "at the same time", in distinct streams. You can see the changes other branch has done in "newfeature" section and the other in the HEAD section.
发生的事情是发生了合并冲突:两个分支在不同的流中“同时”更改了文件。您可以在“newfeature”部分和 HEAD 部分中看到其他分支所做的更改。
What you need to do is to edit that file so that it will contain the contents that you want, add that to be followed and then commit that. This is known as a merge commit.
您需要做的是编辑该文件,使其包含您想要的内容,添加要遵循的内容,然后提交。这称为合并提交。
Now, what I told above is doing a merge by hand, "manually". It is possibly the easiest to understand. You can also use git mergetool
command to do that with a visual tool, if configured, or use "git merge" with some strategy that will tell it how to handle the conflict.
现在,我上面所说的是“手动”手动合并。这可能是最容易理解的。您还可以使用git mergetool
命令通过可视化工具(如果已配置)来执行此操作,或者使用“git merge”以及一些告诉它如何处理冲突的策略。
回答by dureuill
Git's automatic merge failed. This usually happens when changes occur to the same file at the same time in different branches/repositories when trying to merge branches/push content.
Git 的自动合并失败。当尝试合并分支/推送内容时,这通常发生在不同分支/存储库中的同一文件同时发生更改时。
The modifications made to .gitignore on the branch newfeature conflits with the one made on master.
The line: <<<<<<< HEAD
indicates the modifications made on master, which follow this line, while the line >>>>>>> newfeature
indicates the modifications made on newfeature, which precede this line. The two modifications are separated by =======
.
在分支 newfeature 上对 .gitignore 所做的修改与在 master 上所做的修改相冲突。行:<<<<<<< HEAD
表示在 master 上所做的修改,在此行之后,而行>>>>>>> newfeature
表示对 newfeature 所做的修改,在此行之前。这两个修改以 分隔=======
。
You should edit manually the file and keep/merge what is useful in each of the two parts. Then you should commit (after removing the <<<<HEAD
, =====
and >>>newfeature
lines).
您应该手动编辑文件并保留/合并两部分中有用的内容。然后你应该提交(删除<<<<HEAD
,=====
和>>>newfeature
行后)。
回答by Wooble
Use git mergetool
to resolve the conflict (or just fix it yourself manually; this isn't a particularly hard case to resolve), then re-commit.
使用git mergetool
来解决冲突(或者只是自己手工修复,这并不是一个特别难的情况下,以解决),然后重新提交。
回答by knittl
Fix the conflicts in the .gitignore
file, add the updated version and then commit:
修复.gitignore
文件中的冲突,添加更新的版本,然后提交:
vim .gitignore
# assuming you want all 4 lines: simply remove the conflict markers (<<<<<<, ======, and >>>>>)
git add .gitignore
git commit
回答by galadog
You should merge your .gitignore by hand, then add it to index by
您应该手动合并您的 .gitignore,然后将其添加到索引中
$ git add .gitignore
You can get the basics of merging here: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
您可以在此处获得合并的基础知识:http: //git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging