24

リポジトリがロックされているように見えるこの状態を取り除くことができません。HEAD~1 にリセットした後、この単一のファイルが変更されているという通知を受け取り続けます。「追加」と「チェックアウト」は影響しません。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 に答える