打標籤
git tag -m "Say bye-bye to all previous practice." old_practice //引號裡是註釋
本地刪除不是真的刪除,對暫存區和版本庫,沒有任何影響
rm 刪除工作空間內容
git ls-files 檢視 暫存區(版本庫)中還是有刪除的內容
可以使用git checkout -- <file> 找回剛剛刪除的檔案
真正刪除 ,在執行了rm 後 執行
$ git rm detached-commit.txt hack-1.txt new-commit.txt test.ini welcome.txt
rm 'detached-commit.txt'
rm 'hack-1.txt'
rm 'new-commit.txt'
rm 'test.ini'
rm 'welcome.txt'
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: detached-commit.txt
# deleted: new-commit.txt
# deleted: test.ini
# deleted: welcome.txt
#
執行git rm 後再執行 git commit 就真刪除了
$ git commit -m "delete trash files.(useing: git rm)"
[master 124a538] delete trash files.(useing: git rm)
4 files changed, 5 deletions(-)
delete mode 100644 detached-commit.txt
delete mode 100644 new-commit.txt
delete mode 100644 test.ini
delete mode 100644 welcome.txt
歷史版本中檢視刪除的檔案
$ git ls-files --with-tree=HEAD^
detached-commit.txt
new-commit.txt
test.ini
welcome.txt
歷史版本中檢視刪除檔案的內容
$ git cat-file -p HEAD^:welcome.txt
Hello .
Nice to meet you
快速標記刪除實驗
版本庫恢復上一次提交 暫存區也恢復上一次 工作區也恢復上一次提交
$ git reset --hard HEAD^
HEAD is now at a7e643d Merge commit 'dcdf192'
恢復儲存的進度 加-q是安靜模式
git stash apply -q
刪除本地所有檔案 依然只刪除工作區的
rm *.*
$ git status -s
D detached-commit.txt
AD hack-1.txt
D new-commit.txt
D test.ini
D welcome.txt
然後執行 git add -u 將工作區中修改或者刪除的被版本庫跟宗的檔案 的變更記錄到暫存區
$ git add -u
檢視狀態,全部標記為下次提交都刪除
$ git status -s
D detached-commit.txt
D new-commit.txt
D test.ini
D welcome.txt
提交刪除
$ git commit -m "delete trash files.(useing: git add -u)"
[master 509a15e] delete trash files.(useing: git add -u)
4 files changed, 5 deletions(-)
delete mode 100644 detached-commit.txt
delete mode 100644 new-commit.txt
delete mode 100644 test.ini
delete mode 100644 welcome.txt