當要在工作區刪除乙個檔案並提交到版本庫中時,就需要用到git rm命令了。不同於git add新增或修改乙個檔案,git rm是刪除乙個檔案,並結合git commit將刪除改動提交到版本庫中。
改動之前工作區:
➜ code git:(master) ll
total 8
drwxr-xr-x 5 mymac staff 160 9 7 08:00 ./
drwxr-xr-x+ 64 mymac staff 2048 9 7 08:36 ../
drwxr-xr-x 13 mymac staff 416 9 7 08:36 .git/
drwxr-xr-x 3 mymac staff 96 8 3 15:29 cliff_demo/
-rw-r--r-- 1 mymac staff 21 8 25 18:12 master1.txt
現在建立乙個名為 __init__.py 的檔案,並將它提交到版本庫中。
➜ code git:(master) touch __init__.py
➜ code git:(master) ✗ ll
total 8
drwxr-xr-x 6 mymac staff 192 9 7 08:38 ./
drwxr-xr-x+ 64 mymac staff 2048 9 7 08:38 ../
drwxr-xr-x 13 mymac staff 416 9 7 08:38 .git/
-rw-r--r-- 1 mymac staff 0 9 7 08:38 __init__.py
drwxr-xr-x 3 mymac staff 96 8 3 15:29 cliff_demo/
-rw-r--r-- 1 mymac staff 21 8 25 18:12 master1.txt
➜ code git:(master) ✗ git add __init__.py
➜ code git:(master) ✗ git commit -m "demo create a python file."
[master b231ce6] demo create a python file.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 __init__.py
➜ code git:(master) ll
total 8
drwxr-xr-x 6 mymac staff 192 9 7 08:38 ./
drwxr-xr-x+ 64 mymac staff 2048 9 7 08:38 ../
drwxr-xr-x 13 mymac staff 416 9 7 08:38 .git/
-rw-r--r-- 1 mymac staff 0 9 7 08:38 __init__.py
drwxr-xr-x 3 mymac staff 96 8 3 15:29 cliff_demo/
-rw-r--r-- 1 mymac staff 21 8 25 18:12 master1.txt
使用 git rm 將版本庫中的 __init__.py檔案刪除
使用git rm 命令後,工作區對應的檔案會被刪除。
➜ code git:(master) git rm __init__.py
rm '__init__.py'
➜ code git:(master) ✗ ll
total 8
drwxr-xr-x 5 mymac staff 160 9 7 08:41 ./
drwxr-xr-x+ 64 mymac staff 2048 9 7 08:41 ../
drwxr-xr-x 13 mymac staff 416 9 7 08:41 .git/
drwxr-xr-x 3 mymac staff 96 8 3 15:29 cliff_demo/
-rw-r--r-- 1 mymac staff 21 8 25 18:12 master1.txt
這時版本庫中的檔案仍未刪除,僅僅只是工作區刪除了。我們需要繼續使用 git commit 將刪除修改提交到版本庫中。
➜ code git:(master) ✗ git commit -m "demo delete python file."
[master 45669b1] demo delete python file.
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 __init__.py
➜ code git:(master)
至此刪除版本庫中的乙個檔案的任務就算完成了。 git 刪除檔案
本地同步好最新的 修改或者替換你那個有問題的檔案 直接修改 git pull git add git commit m modified file git push origin head your remote branch 括號內可以省略 刪除的話 git pull git rm git com...
git 刪除檔案
本地 與遠端git倉庫端的 已經是同步 一致 的了。想將本地的某個資料夾刪除,然後同步到遠端git倉庫端 git add git status git commit m 無用的目錄刪除 git push origin master執行完此操作之後,登入到遠端git倉庫端,發現本地刪除的目錄依然存在。...
Git刪除檔案
在git中,刪除檔案也屬於修改操作,因此,要想刪除起作用,那麼之後也要git commit。在git中刪除乙個檔案使用git rm命令。在下圖中,首先建立乙個新檔案,然後新增到倉庫去。現在,我們來刪除這個檔案,從 倉庫中。使用如下命令 git rm test執行該命令成功以後,輸出如下 需要注意的是...