簡體   English   中英

重命名文件后自動刪除GIT存儲庫中的文件

[英]Automatically remove files in GIT repository after renaming them

我通常用以下方法

$ mv file1.py file2.py
$ git add .
$ git rm file1.py

如何跳過最后一步? 這樣,每當我添加新的名稱文件時,它將自動刪除git存儲庫中的舊文件file1.py

我知道我可以做git mv file1.py file2.py 但是在我的工作流程中,我傾向於執行許多mv命令,並且更喜歡在最后添加並提交它們。

如果要git add -u所有當前文件,可以使用git add -u因此可以嘗試以下組合:

git add . #add new files
git add -u #stage removed files

 lol4t0@lol4t0-VirtualBox:~/gtets$ mv foo bar lol4t0@lol4t0-VirtualBox:~/gtets$ git status On branch master 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: foo Untracked files: (use "git add <file>..." to include in what will be committed) bar no changes added to commit (use "git add" and/or "git commit -a") lol4t0@lol4t0-VirtualBox:~/gtets$ git add -u lol4t0@lol4t0-VirtualBox:~/gtets$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) deleted: foo Untracked files: (use "git add <file>..." to include in what will be committed) bar lol4t0@lol4t0-VirtualBox:~/gtets$ git add . lol4t0@lol4t0-VirtualBox:~/gtets$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: foo -> bar 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM