无法合并文件。如何将其与Git合并?
答案 0 :(得分:2)
错误消息是(Git Faq):
fatal: Entry 'frotz' not uptodate. Cannot merge.
这意味着您对“
frotz
”进行了本地修改,这些修改会在结帐时丢失。您可以向-m
提供“git checkout
”选项,该选项会尝试三向合并。有时解决方案是提交。
也在git checkout
中说明。
-m
--merge
切换分支时,如果对当前分支和要切换到的分支之间的一个或多个文件进行本地修改,则命令拒绝切换分支以保留上下文中的修改
所以合并过程将是:
git checkout -m mytopic
Auto-merging frotz
在这种三向合并之后,本地修改不在索引文件中注册,因此
git diff
将显示自新分支提示以来您所做的更改。< / p>在使用
-m
选项切换分支期间发生合并冲突时,您会看到如下内容:
$ git checkout -m mytopic
Auto-merging frotz
ERROR: Merge conflict in frotz
fatal: merge program failed
此时,
git diff
显示了上一个示例中干净地合并的更改,以及冲突文件中的更改。
编辑并解决冲突,并像往常一样用git add
标记解决冲突:
$ edit frotz
$ git add frotz
答案 1 :(得分:1)
合并git中的文件:
CONFLICT
时有x
,并且您应该在继续合并之前修复此冲突。<<<
)。git add filewithconfict
git commit -m "Merged master branch"
以下是合并会话的示例:
Last login: Mon Nov 30 17:51:55 on ttys002
KidA% cd Desktop
KidA% mkdir merge.git
KidA% cd merge.git
KidA% git init
Initialized empty Git repository in /Users/jkp/Desktop/merge.git/.git/
KidA% echo "foo" > test.file
KidA% git add *
KidA% git commit -m "Initial commit"
[master (root-commit) 55f61fc] Initial commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 test.file
KidA% git branch
* master
KidA% git checkout -b topic
Switched to a new branch 'topic'
KidA% echo "bar" > test.file
KidA% git commit -a -m "Topic commit"
[topic 6c524f3] Topic commit
1 files changed, 1 insertions(+), 1 deletions(-)
KidA% git checkout master
Switched to branch 'master'
KidA% echo "foobar" > test.file
KidA% git commit -a -m "Conflicting commit"
[master a660160] Conflicting commit
1 files changed, 1 insertions(+), 1 deletions(-)
KidA% git checkout topic
Switched to branch 'topic'
KidA% git merge master
Auto-merging test.file
CONFLICT (content): Merge conflict in test.file
Automatic merge failed; fix conflicts and then commit the result.
KidA% vim test.file
test.file before resolve:
<<<<<<< HEAD
bar
=======
foobar
>>>>>>> master
test.file after resolve:
foobar
KidA% git add test.file
KidA% git commit -m "Merged master branch"
[topic 44c0cb6] Merged master branch