我跑了下面的命令,並獲得困惑由git diff HEAH
輸出以及git diff
「錯誤的」通過git的差異HEAD和git的差異輸出
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo
$ git init
Initialized empty Git repository in C:/Users/Athrun/Desktop/path/to/my/workspace /demo/.git/
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ echo "Hello World" > welcome.txt
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ git add welcome.txt
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ git commit -m "\"Hello World\" committed"
[master (root-commit) eb00b00] "Hello World" committed
1 file changed, 1 insertion(+)
create mode 100644 welcome.txt
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ git rm --cached welcome.txt
rm 'welcome.txt'
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ git diff HEAD
diff --git a/welcome.txt b/welcome.txt
deleted file mode 100644
index 557db03..0000000
--- a/welcome.txt
+++ /dev/null
@@ -1 +0,0 @@
-Hello World
[email protected] MINGW64 ~/Desktop/path/to/my/workspace/demo (master)
$ git diff
基本上,我初始化的回購,創建與串的文件「Hello World」並提交了該文件。然後,我運行命令git rm --cached welcome.txt
刪除「文件」(不確定我是否可以在此處稱爲「文件」)在暫存區域中。然後我運行了兩個命令git diff HEAD
和git diff
來比較HEAD和臨時區域的變化。
我在這裏理解的是,工作目錄和HEAD具有相同版本的文件,`git diff HEAD'應該不顯示任何內容,而'git diff'應該顯示「Hello World」已刪除。
但是,輸出正好相反。
@PetSerAI謝謝你的回答,我沒有意識到,git rm --cached不能解決這個文件。這有很大幫助。 – user1888955