简体   繁体   English

为什么 git 会修改我的文件? 我如何撤消它?

[英]Why does git modify my files? How do i undo it?

Hey, so I'm a complete git newbie here, the most advanced thing I've done is just basic pulls/pushes.etc嘿,所以我在这里是一个完整的 git 新手,我做过的最先进的事情只是基本的 pulls/pushes.etc

For reasons I don't understand one of my commits edited a heap of files, including embedded into the file the edits I made since the last commit, for example:由于我不明白我的一个提交编辑了一堆文件的原因,包括嵌入到文件中我自上次提交以来所做的编辑,例如:

foo.txt: foo.txt:

bar

then if i edited it to:然后,如果我将其编辑为:

foobar

the file upon committing got changed to something like:提交时的文件已更改为:

<<<<<<< HEAD
bar
=======
foobar
>>>>>>> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

with the X's being the commit code or whatever. X 是提交代码或其他什么。

What are these edits to my source files, and how do I get rid of them?我的源文件的这些编辑是什么,我如何摆脱它们?

Thanks for any help with this感谢您对此的任何帮助

Those represent merge conflicts.这些代表合并冲突。 Your commit is causing conflicts to the file.您的提交导致文件冲突。

<<<<<<< HEAD
bar

represents what is already in the HEAD表示 HEAD 中已有的内容

foobar
>>>>>>> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

shows what you are trying to merge.显示您要合并的内容。

Look here at Resolving a Merge section: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging看这里解决合并部分: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

In addition to manojlds:除了manojlds:

You can specify to have the version of the common ancestor in your merge conflict (separated by pipes |||||), by using the following configuration:您可以使用以下配置指定在合并冲突中具有共同祖先的版本(由管道 ||||| 分隔):

git config merge.conflictstyle diff3

This would make the conflict look like:这将使冲突看起来像:

<<<<<<< HEAD
roses are #ff0000
violets are #0000ff
|||||||
roses are red
violets are blue
=======
Roses are red,
Violets are blue,
>>>>>>> master

Check out more onKevin's Blog凯文的博客上查看更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM