git mv
行為:
1.創建一個和之前文件內容一樣的文件,文件名為新的文件名
2.將原來的文件刪除
3.將刪除的文件添加到暫存區
4.將新建的文件添加到暫存區
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: a -> a1
提交:
直接 git commit -m ''
[master 863356d] rename a to a1
1 file changed, 0 insertions(+), 0 deletions(-)
rename a => a1 (100%)
$ git status
On branch master
nothing to commit, working directory clean
恢復:
1. 恢復暫存區(git reset HEAD oldName)
2. 將新添加的文件從暫存區移除(git reset HEAD newName)
3. 將原來的文件從暫存區恢復到工作區(git checout -- oldName)
3. 從工作區刪除新添加的這個文件(rm newName)
$ git reset HEAD a Unstaged changes after reset: D a $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: a1 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: a $ git reset HEAD a1 Unstaged changes after reset: D a $ 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: a Untracked files: (use "git add <file>..." to include in what will be committed) a1 no changes added to commit (use "git add" and/or "git commit -a") $ git checkout -- a $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) a1 nothing added to commit but untracked files present (use "git add" to track) $ rm a1 $ git status On branch master nothing to commit, working directory clean
直接調用系統的mv
行為:
只是重命名了一個文件
$ mv a a1 $ 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: a Untracked files: (use "git add <file>..." to include in what will be committed) a1 no changes added to commit (use "git add" and/or "git commit -a")
提交:
1.把新文件和舊文件加入暫存區
2.提交暫存區的改動
$ git add a a1 $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: a -> a1 $ git commit -m 'rename a to a1' [master 8b02e6a] rename a to a1 1 file changed, 0 insertions(+), 0 deletions(-) rename a => a1 (100%) $ git status On branch master nothing to commit, working directory clean
恢復:
1.將舊文件恢復到工作區,git checout -- oldName
2.將新文件刪除, rm newName
$ git checkout -- a $ rm a1 $ git status On branch master nothing to commit, working directory clean
