我通常使用
执行以下操作$ mv file1.py file2.py
$ git add .
$ git rm file1.py
如何跳过最后一步?这样每当我添加新名称时
文件将自动删除git存储库中的旧文件file1.py
。
我知道我可以做git mv file1.py file2.py
。但是在我的工作流程中,我倾向于做很多mv
命令,并且更喜欢在最后添加和提交它们。
答案 0 :(得分:2)
如果您想要暂存所有当前文件,可以使用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