Git删除文件操作

时间:2023-03-09 19:51:18
Git删除文件操作

发现访问量也很大,我稍微修改一下细节,如下:

步骤:

1.git rm xxx

2.git commit

需要注意:是直接rm命令删除后是不可以的,可以用git status 命令尝试一下,效果如图下(创建了test文件,演示了git rm和rm的区别):

::51wang@~/Documents/git/test >>  vi test
::07wang@~/Documents/git/test >> ll
total
-rw-rw-r--. wang wang Apr : getZhihuDaily.py
-rw-rw-r--. wang wang Apr : README.md
-rw-rw-r--. wang wang Apr : test
drwxrwxr-x. wang wang Apr : vim-colors-solarized
-rw-rw-r--. wang wang Apr : vimrc ::09wang@~/Documents/git/test >> git add test
::15wang@~/Documents/git/test >> git commit -m "test"
[master 710da9d] test
file changed, insertion(+)
create mode test ::24wang@~/Documents/git/test >> ls
getZhihuDaily.py README.md test vim-colors-solarized vimrc
::26wang@~/Documents/git/test >> git status
# On branch master
# Your branch is ahead of 'origin/master' by commit.
# (use "git push" to publish your local commits)
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# vim-colors-solarized/
nothing added to commit but untracked files present (use "git add" to track) ::35wang@~/Documents/git/test >> rm test
::30wang@~/Documents/git/test >> git status
# On branch master
# Your branch is ahead of 'origin/master' by commit.
# (use "git push" to publish your local commits)
#
# 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: test
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# vim-colors-solarized/
no changes added to commit (use "git add" and/or "git commit -a") ::33wang@~/Documents/git/test >> git rm test
rm 'test'
::41wang@~/Documents/git/test >> git status
# On branch master
# Your branch is ahead of 'origin/master' by commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: test
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# vim-colors-solarized/ ::47wang@~/Documents/git/test >> git commit -m"rm test"
[master 2953ea2] rm test
file changed, deletion(-)
delete mode test
::00wang@~/Documents/git/test >> git status
# On branch master
# Your branch is ahead of 'origin/master' by commits.
# (use "git push" to publish your local commits)
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# vim-colors-solarized/
nothing added to commit but untracked files present (use "git add" to track)

Git删除文件操作