24

我无法摆脱我的仓库似乎被锁定的状态。在重置到 HEAD~1 后,我不断收到有关此单个文件被修改的通知。'add' 和 'checkout' 没有影响。我有 core.autocrlf 和 core.safecrlf 未设置(空)。

请看下面:

$ git --version
git version 1.7.9.6 (Apple Git-31.1)

$ git status

# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   a_file_name.cpp

以下命令(单独运行)没有影响:

$ git checkout -- a_file_name.cpp
$ git reset a_file_name.cpp
$ git add a_file_name.cpp
$ git reset --hard
$ git clean -n
<nothing>
$ git clean -f
<nothing>

$ git status

# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   a_file_name.cpp

它继续......

我做错什么了?

对下面@Don 的建议的回应(git rm),没有变化,但它是这样的:

$ git rm 
error: 'a_file_name.cpp' has local modifications
(use --cached to keep the file, or -f to force removal)
$ git rm -f a_file_name.cpp
rm 'a_file_name.cpp'
$ git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    a_file_name.cpp
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    a_file_name.cpp
#

$ git commit -m"tmp"
[master 2a9e054] tmp
1 file changed, 174 deletions(-)
delete mode 100644 a_file_name.cpp

$ git status
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    a_file_name.cpp
#

几乎回到 sq.1

4

5 回答 5

7
git commit -a -m "message"

-a 选项将添加所有跟踪的文件并进行修改

于 2013-09-27T09:35:05.900 回答
6

一个对我有用的方法是:

  1. 重新创建我删除的文件。

  2. git add path/filename

  3. git rm --cached path/filename

  4. 删除文件

  5. git add .

  6. git commit --amend # if not on an already pushed branch.

于 2013-11-11T17:56:11.473 回答
2

git运行任何命令时,请确保您与文件位于同一目录中。git或者,您可以对与命令一起使用的文件使用相对或绝对路径。的输出git status 指示文件所在的子目录。我发现您在此处发布的输出没有显示这一点很奇怪。

于 2012-11-29T21:25:19.273 回答
1

您需要修改后的文件中的任何更改吗?git-reset 默认将文件保留在目录树中。

git reset --hard

将使用提交中的文件重置并覆盖工作树中的文件。

您是否在每个步骤之后都进行了 git diff 以查看是否确实存在任何更改?

于 2012-11-29T17:18:59.473 回答
0

如果有问题的文件具有不同的大小写,则可能会发生这种情况。

在我的情况下

README.md readme.md

git 不会让您简单git add ...地更改大小写。

你可以通过做类似的事情来解决这个问题

git mv -f readme.md README.md

于 2021-12-29T23:09:20.247 回答