Git rm命令幾種使用方式

來源:互聯網
上載者:User

1 直接刪除倉庫裡面的檔案,檔案在staged裡面無變化。

git rm 11rm '11'

git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##       deleted:    11#

接著提交,將變化更新到倉庫。git commit

[master 6eb8c6a] delete 11 v1.3 1 file changed, 1 deletion(-) delete mode 100644 11

 

2 刪除倉庫裡面的檔案11,但11已經被修改,還沒有被staged 

$ git rm 11error: '11' has local modifications(use --cached to keep the file, or -f to force removal)

加上-f選項強制移除,--cahed的意思是會刪除staged裡面的檔案,但工作目錄下的對應的檔案會 保留。

$ git rm 11 -frm '11'$ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##       deleted:    11#
重新commit
[master 994b1ee] deleted 11 v1.3 0 files changed delete mode 100644 11

3 刪除staged裡面的檔案,但不刪除工作目錄下的對應檔案。

$ git status # On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##       new file:   11#

$ git rm --cached 11rm '11'

$ git status # On branch master# Untracked files:#   (use "git add <file>..." to include in what will be committed)##       11nothing added to commit but untracked files present (use "git add" to track)

4 git mv 更該檔案名稱

$ git mv 11 12$ git status # On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##       renamed:    11 -> 12#

 相當於做了下面三個命令

$ mv 11 12$ git rm 11$ git add 12

用其他工具批處理改名的話,要記得在提交前刪除老的檔案名稱,再添加新的檔案名稱。

下面我接著手動更新12名至13名,再git status發現,Git 會意識到這是兩次連續的改名,11->12->13 ,很智能。

$ mv 12 13$ git rm 12rm '12'$ git add 13$ $ $ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##       renamed:    11 -> 13#

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.