简体   繁体   中英

Automatically remove files in GIT repository after renaming them

I usually does the following with

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

How can I skip the last step? So that whenever I add the newly name files it will automatically remove the old one file1.py in the git repository.

I know I can do git mv file1.py file2.py . But in my workflow I tend to do many mv commands and prefer to add and commit them at the very end.

If you want to stage all current files you can do it with git add -u So you can try the following combination:

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

Example

 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM