无法结帐,文件未合并

问题描述 投票:0回答:9

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

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")
git version-control merge-conflict-resolution
9个回答
216
投票

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

git reset -- first_Name.txt
git checkout -- first_Name.txt

37
投票

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

git rm first_file.txt

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

rm -r explore_california

33
投票

以下对我有用

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

成功了


21
投票

状态告诉您该怎么做。

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

您可能应用了隐藏项或其他导致冲突的内容。

添加、重置或 rm。


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}

步骤3:

git checkout .

0
投票

就我而言,我发现我需要 -f 选项。比如下面这样:

git rm -f first_file.txt

摆脱“需要合并”错误。


0
投票

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

第1步:git重置Head 第 2 步:git add .


0
投票

它对我有用。

它将从当前 HEAD 恢复文件

    git restore -S -W file_Name.txt
© www.soinside.com 2019 - 2024. All rights reserved.