无法结账,文件未合并。

135
我正在尝试从我的工作目录中删除文件,但在使用以下命令后:
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")

1
如果你想删除 explore_california,只需执行 rm -r explore_california,因为它没有被 Git 跟踪。 - brokenfoot
它让我一个个地删除超过50个文件,我还在不停地按y? - Naseer
但最终它成功了。谢谢。 - Naseer
@khan:请查看此链接,了解为什么它会要求您的权限来删除文件:http://superuser.com/questions/345923/remove-file-without-asking - brokenfoot
2
可能是重复的问题,参考Git:无法撤消本地更改(错误:路径...未合并) - Stewart
显示剩余3条评论
9个回答

204

如果你想放弃对文件的修改,可以执行以下操作:

git reset first_Name.txt
git checkout first_Name.txt

2
需要双破折号参数吗?git reset -- first_name.txt 和 git checkout -- first_name.txt - demented hedgehog
3
你只需要使用 -- 来将你想要检出的树与你想要检出的文件分开。如果需要更详细的解释,请参考这里:https://dev59.com/YWYr5IYBdhLWcg3w499- - cristianoms
7
为了确保文件名不与你的分支/标签/提交之一相同,我认为更安全的做法是使用双短线 git reset -- first_Name.txtgit checkout -- first_Name.txt。请注意,这不会改变原来的意思。 - joeytwiddle

36

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

git rm first_file.txt

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

rm -r explore_california

32

以下方法对我有效

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

它起作用了


20

状态告诉你该做什么。

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

你可能应用了一个stash或其他引起冲突的东西。

要么添加,重置或删除。


3
好的,我会尽力进行翻译。以下是需要翻译的内容:"Exactly I applied a stash. Now the question is when to use add, when reset and when do I use rm? For example, I don't want to keep the stashed version but the version from upstream instead?"我的确应用了一个stash。现在问题是何时使用add、何时使用reset以及何时使用rm?例如,我不想保留存储的版本,而是要使用来自上游的版本。 - Pro Backup

4

我不认为执行

 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

这条命令适用于你。


1
步骤1:
git stash -u

步骤2:
git stash drop stash@{1}

步骤三:
git checkout .

0
在我的情况下,我发现我需要使用-f选项。例如以下内容:
git rm -f first_file.txt

为了消除“需要合并”的错误。


0

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

步骤1:git reset Head 步骤2:git add .


0

这对我有效。

它将从当前 HEAD 恢复文件。

    git restore -S -W file_Name.txt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接