Delete and move
TweetPosted on Sunday Mar 09, 2014 at 09:20AM in Technology
Assume this:
kyle-no-MacBook:gitprac5 kyle$ ls -l total 8 -rw-r--r--+ 1 kyle staff 5 3 9 09:27 hoge.txt kyle-no-MacBook:gitprac5 kyle$ cat hoge.txt hoge kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
Delete
Delete from working tree
kyle-no-MacBook:gitprac5 kyle$ rm hoge.txt kyle-no-MacBook:gitprac5 kyle$ 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: hoge.txt # no changes added to commit (use "git add" and/or "git commit -a") kyle-no-MacBook:gitprac5 kyle$
Add deletion to index
kyle-no-MacBook:gitprac5 kyle$ git rm hoge.txt rm 'hoge.txt' kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
Commit
kyle-no-MacBook:gitprac5 kyle$ git commit -m 'delete' [master 8793936] delete 1 file changed, 1 deletion(-) delete mode 100644 hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$ ls -l kyle-no-MacBook:gitprac5 kyle$
Move / Rename
kyle-no-MacBook:gitprac5 kyle$ git mv hoge.txt hige.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: hoge.txt -> hige.txt # kyle-no-MacBook:gitprac5 kyle$
- Another identical operation:
kyle-no-MacBook:gitprac5 kyle$ mv hoge.txt hige.txt kyle-no-MacBook:gitprac5 kyle$ git rm hoge.txt rm 'hoge.txt' kyle-no-MacBook:gitprac5 kyle$ git add hige.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: hoge.txt -> hige.txt # kyle-no-MacBook:gitprac5 kyle$
Tags: git