将上游更改合并回我的分支时遇到问题

发布于 2024-11-03 03:51:14 字数 607 浏览 3 评论 0原文

我在尝试将上游更改合并回我的分支时遇到冲突,并且我不确定如何解决它们。

我创建了自己的叉子。我克隆了它。我对我的叉子上的分支进行了更改,提交并推送。但后来主分支更新了,我尝试通过像这样合并上游来更新我自己的分支:

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

ぽ尐不点ル 2024-11-10 03:51:14

您所看到的意味着自动合并无法解决文件中的冲突。您需要手动解决这些冲突。运行 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 or git gui.

傲娇萝莉攻 2024-11-10 03:51:14

“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.

╭⌒浅淡时光〆 2024-11-10 03:51:14

在 Git 中,有时合并拒绝甚至开始以保护您的本地更改。这可能在两种情况下发生:

  • 您的存储库中有未提交的更改与合并冲突。 git 将拒绝合并并显示以下消息:

    错误:您对以下文件的本地更改将被合并覆盖:
          foo
    请在合并之前提交您的更改或隐藏它们。
    正在中止
    
    
    

    然后你必须先提交更改(git commit -agit add + git commit),或者将它们隐藏起来使用 git stash save

  • 正在进行一些未完成的合并操作。例如,存在一些冲突

    自动合并 foo
    冲突(内容): foo 中的合并冲突
    自动合并失败;修复冲突,然后提交结果。
    
    
    

    并且您尚未完成冲突解决(通过编辑文件并将其标记为使用 git add 已解决,或通过 git mergetool 使用某些图形合并工具)并且没有' t 使用 git commit -a 创建最终合并提交,或使用 git reset --hard 中止合并(注意:这将丢弃所有你改变了,你就会失去解决问题的工作冲突!!!)。

    或者您刚刚运行第二个 git merge 太快,或者使用 git merge 而不是 git commit 来创建合并提交。< /p>

    错误:“合并”是不可能的,因为您有未合并的文件。
    提示:将它们修复在工作树中,
    提示:然后使用 'git add/rm ' 作为
    提示:适合标记解决方案并进行提交,
    提示:或使用“git commit -a”。
    fatal:由于未解决的冲突而退出。
    
    
    

    按照 Junio C Hamano 的旧完成合并的乐趣文章中的描述解决冲突使用 git commit 完成合并,或者放弃合并,或者将其隐藏起来。然后,如果您打算创建第二次合并,就可以做到。

旁注:默认情况下,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:

    error: Your local changes to the following files would be overwritten by merge:
            foo
    Please, commit your changes or stash them before you can merge.
    Aborting
    

    Then you have to either commit the changes first (git commit -a or git add + git commit), or stash them away with git stash save.

  • You are in the middle of some unfinished merge-y operation. There was some conflict, for example

    Auto-merging foo
    CONFLICT (content): Merge conflict in foo
    Automatic merge failed; fix conflicts and then commit the result.
    

    and you have not finished resolving conflicts (by editing files and marking them as resolved with git add, or using some graphical merge tool via git mergetool) and didn't create a final merge commit with git commit -a, or aborted the merge with git 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 used git merge instead of git commit to create a merge commit.

    error: 'merge' is not possible because you have unmerged files.
    hint: Fix them up in the work tree,
    hint: and then use 'git add/rm ' as
    hint: appropriate to mark resolution and make a commit,
    hint: or use 'git commit -a'.
    fatal: Exiting because of an unresolved conflict.
    

    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).

善良天后 2024-11-10 03:51:14

第二次运行 git commit(添加文件后),而不是 git merge。

此外,冲突解决方案将创建文件来帮助您合并。另请参阅 git mergetool 。

Run git commit (after adding the files) the second time, not git merge.

Also the conflict resolution will create files to help you merge. See also git mergetool.

我很坚强 2024-11-10 03:51:14

解决合并后,您需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文