将上游更改合并回我的分支时遇到问题
我在尝试将上游更改合并回我的分支时遇到冲突,并且我不确定如何解决它们。
我创建了自己的叉子。我克隆了它。我对我的叉子上的分支进行了更改,提交并推送。但后来主分支更新了,我尝试通过像这样合并上游来更新我自己的分支:
$ cd repo-name
$ git remote add upstream git://github.com/username/repo-name.git
$ git fetch upstream
$ git merge upstream/master
合并说文件存在一些问题,并且自动合并不起作用。它告诉我自己修复它并重新合并。所以我实际上去了主分支的 GitHub 上的(上游)存储库,并将新文件的所有代码复制到我的分支上的文件中,并尝试再次合并。然后,git 给了我这个错误:
致命:“合并”是不可能的,因为您有未合并的文件。 请在工作树中修复它们,然后使用 'git add/rm ' 作为 适合标记解决方案并进行提交,或使用“git commit -a”。
我是否遗漏了一些论点?我是不是在做蠢事? “未合并的文件”是什么意思?合并的全部意义不就是合并文件吗?我必须在合并之前提交更改吗?
I'm running into conflicts while trying to merge upstream changes back into my branch and I'm not sure how to resolve them.
I created my own fork. I cloned it. I made changes to the branch on my fork, committed, and pushed. But then the main fork updated, and I tried to update my own fork by merging upstream in like so:
$ cd repo-name
$ git remote add upstream git://github.com/username/repo-name.git
$ git fetch upstream
$ git merge upstream/master
The merge says that there's some problem with a file and auto-merging doesn't work. It tells me to fix it myself and re-merge. So I actually went to the (upstream) repository on GitHub of the main fork and copied all the code of the new file into the file on my fork, and tried to merge again. Then, git gives me this error:
fatal: 'merge' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm ' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Is there some argument I'm leaving out? Am I doing something stupid? What does it mean by "unmerged files?" Isn't the whole point of merging to merge files? Do I have to commit my changes before I merge?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您所看到的意味着自动合并无法解决文件中的冲突。您需要手动解决这些冲突。运行 git mergetool 或 git gui 。
What you are seeing means that automatic merge could not resolve the conflicts in the files. You need to resolve these conflicts manually. Run
git mergetool
orgit gui
.“git merge”命令尝试将另一个分支的更改合并到当前分支中。如果合并是干净的,意味着没有冲突,它将提交。由于您的合并确实存在冲突,因此它没有提交。你需要解决冲突。
从上游存储库中提取副本是一种方法 - 接受上游存储库的版本。您可以在 git 中使用“git checkout --theirsconflicting_file.txt”来执行此操作,
编辑文件以将其变成您想要的形状是另一种方法。
修复后,您需要使用“git addconflicting_file.txt”进行添加,然后提交。然后你的工作副本就干净了,并准备好进行更多的黑客攻击。祝你好运。
The "git merge" command tries to incorporate changes from another branch onto the present branch. If the merge is clean, meaning no conflicts, it will commit. Since your merge did have conflicts, it didn't commit. You need to resolve the conflict.
Pulling the copy from the upstream repo is one way to do that - by accepting the upstream repo's version. You can do that within git using "git checkout --theirs conflicting_file.txt"
Editing the file to get it into the shape you want is another way.
Once it's fixed, you need to add using "git add conflicting_file.txt" then commit. Then your working copy is clean and ready for more hacking. Good luck.
在 Git 中,有时合并拒绝甚至开始以保护您的本地更改。这可能在两种情况下发生:
您的存储库中有未提交的更改与合并冲突。 git 将拒绝合并并显示以下消息:
您正在进行一些未完成的合并操作。例如,存在一些冲突
旁注:默认情况下,git-aware shell 提示会显示您是否正在进行合并、变基或应用补丁(
git am
操作)。您还可以将其配置为显示工作目录是否脏(与最新版本不同,即 HEAD)。In Git there are cases merge refuses to even start in order to protect your local changes. This may happen in two cases:
You have uncommitted changes in you repository that conflict with merge. The git will refuse to do a merge with the following message:
Then you have to either commit the changes first (
git commit -a
orgit add
+git commit
), or stash them away withgit stash save
.You are in the middle of some unfinished merge-y operation. There was some conflict, for example
and you have not finished resolving conflicts (by editing files and marking them as resolved with
git add
, or using some graphical merge tool viagit mergetool
) and didn't create a final merge commit withgit commit -a
, or aborted the merge withgit reset --hard
(NOTE: this will discard all you changes, and you will loose work done on resolving conflicts!!!).Or you have just run second
git merge
too fast, or usedgit merge
instead ofgit commit
to create a merge commit.Resolve conflicts as described e.g. in old Fun with completing a merge article by Junio C Hamano and finalize a merge with
git commit
, or discard a merge, or stash it away. Then if you meant to create this second merge, you can do it.Sidenote: by default git-aware shell prompt shows if you are in the middle of merge, rebase or applying patches (
git am
operation). You can also configure it to show if the working directory is dirty (different from latest version, i.e. HEAD).第二次运行 git commit(添加文件后),而不是 git merge。
此外,冲突解决方案将创建文件来帮助您合并。另请参阅 git mergetool 。
Run
git commit
(after adding the files) the second time, notgit merge
.Also the conflict resolution will create files to help you merge. See also
git mergetool
.解决合并后,您需要使用 git add 将已更改的文件添加到索引,然后提交(如消息所述)。这对 git 说“是的,我真的想做出这些改变”。
请记住,如果您使用的是命令行界面,请务必在提交(通常或提交合并)之前使用 git add 。像 Magit 这样的前端可以为你简化这个过程,这样你就不必担心每次都输入“git add”。
After you've resolved a merge, you need to use
git add
to add the files you've changed to the index, and then commit (like the message says). This says to git "Yes, I really do want to make these changes".Remember, always use
git add
before committing (either normally or committing a merge), if you're using the command line interface. Frontends like magit can streamline this for you so you don't have to worry about typing "git add" every time.