【问题标题】:Cannot checkout, file is unmerged无法签出,文件未合并
【发布时间】:2023-03-10 08:11:01
【问题描述】:

我正在尝试从我的工作目录中删除该文件,但在使用以下命令后

git checkout file_Name.txt

我收到以下错误消息

error: path 'first_Name.txt' is unmerged

这是什么以及如何解决?

以下是我的 git 状态

$ git status
On branch master
You are currently reverting commit f200bf5.
  (fix conflicts and run "git revert --continue")
  (use "git revert --abort" to cancel the revert operation)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:      first_file.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        explore_california/

no changes added to commit (use "git add" and/or "git commit -a")

【问题讨论】:

  • 移动到暂存索引但我无法清理文件夹 explore_california/
  • 如果你想删除explore_california,那么只需执行rm -r explore_california,因为它没有被git跟踪。
  • 这要求我单独删除 50 多个文件,而我仍在按 y?
  • 但它终于奏效了。谢谢

标签: git version-control merge-conflict-resolution


【解决方案1】:

如果你想放弃你对文件所做的修改,你可以这样做:

git reset first_Name.txt
git checkout first_Name.txt

【讨论】:

  • 需要双连字符 arg 吗? git reset -- first_name.txt 和 git checkout -- first_name.txt
  • 您只使用-- 将要检出的树与要检出的文件分开。如需更深入的解释,请在此处抢购:stackoverflow.com/questions/13321458/…
  • 我认为使用双连字符 git reset -- first_Name.txtgit checkout -- first_Name.txt 更安全,以防文件名与您的分支/标签/提交之一相同。
【解决方案2】:

从 git 中删除跟踪的文件(first_file.txt):

git rm first_file.txt

要删除未跟踪的文件,请使用:

rm -r explore_california

【讨论】:

    【解决方案3】:

    以下对我有用

    git reset HEAD
    

    我收到以下错误

    git stash
    src/config.php: needs merge
    src/config.php: needs merge
    src/config.php: unmerge(230a02b5bf1c6eab8adce2cec8d573822d21241d)
    src/config.php: unmerged (f5cc88c0fda69bf72107bcc5c2860c3e5eb978fa)
    

    然后我跑了

    git reset HEAD
    

    成功了

    【讨论】:

      【解决方案4】:

      状态告诉你该怎么做。

      Unmerged paths:
        (use "git reset HEAD <file>..." to unstage)
        (use "git add <file>..." to mark resolution)
      

      您可能应用了隐藏或其他导致冲突的东西。

      添加、重置或 rm。

      【讨论】:

      • 正是我应用了一个存储。现在的问题是什么时候使用add,什么时候使用reset,什么时候使用rm?例如,我不想保留隐藏的版本,而是保留来自上游的版本?
      【解决方案5】:

      我不认为执行

       git rm first_file.txt
      

      是个好主意。

      1. 当 git 通知你的文件被取消合并时,你应该确保你已经提交了它。

      2. 然后打开冲突文件:

        cat first_file.txt

      3. 修复冲突

      4.

      git add file

      git commit -m "fix conflict"
      

      5。 git push

      它应该适合你。

      【讨论】:

        【解决方案6】:

        第 1 步:

        git stash -u
        

        第 2 步:

        git stash drop stash@{1}
        

        第 3 步:

        git checkout .
        

        【讨论】:

          【解决方案7】:

          就我而言,我发现我需要 -f 选项。如:

          git rm -f first_file.txt
          

          摆脱“需要合并”错误。

          【讨论】:

            【解决方案8】:

            我通过以下 2 个简单步骤解决了问题:

            第 1 步:git reset 头部 第 2 步:git 添加。

            【讨论】:

              猜你喜欢
              • 2011-10-11
              • 1970-01-01
              • 1970-01-01
              • 2013-12-16
              • 2017-09-09
              • 2020-10-25
              • 1970-01-01
              • 2013-12-09
              • 2021-07-07
              相关资源
              最近更新 更多