亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在git中處理文件重命名

在git中處理文件重命名

Git
湖上湖 2019-10-14 10:17:41
我讀過在git中重命名文件時,應提交所有更改,執行重命名,然后暫存重命名的文件。Git將從內容中識別文件,而不是將其視為新的未跟蹤文件,并保留更改歷史記錄。但是,今晚僅此一次,我最終恢復為git mv。> $ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##   modified:   index.html#將我在Finder中的樣式表從重命名iphone.css為mobile.css> $ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##   modified:   index.html## Changed but not updated:#   (use "git add/rm <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##   deleted:    css/iphone.css## Untracked files:#   (use "git add <file>..." to include in what will be committed)##   css/mobile.css所以git現在認為我已經刪除了一個CSS文件,并添加了一個新文件。不是我想要的,讓撤消重命名,讓git完成工作。> $ git reset HEAD .Unstaged changes after reset:M   css/iphone.cssM   index.html回到我開始的地方。> $ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##   modified:   index.html#讓我們git mv改為使用。> $ git mv css/iphone.css css/mobile.css> $ git status# On branch master# Changes to be committed:#   (use "git reset HEAD <file>..." to unstage)##   renamed:    css/iphone.css -> css/mobile.css## Changed but not updated:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##   modified:   index.html#看起來我們很好。那么,為什么在我使用Finder時git第一次沒有識別出重命名?
查看完整描述

3 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

您必須將兩個修改后的文件添加到索引,然后git才能將其識別為移動。


mv old new和之間的唯一區別git mv old new是git mv還將文件添加到索引中。


mv old new那git add -A本來也可以


請注意,您不能只使用它,git add .因為那不會為索引添加刪除內容。


查看完整回答
反對 回復 2019-10-14
  • 3 回答
  • 0 關注
  • 673 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號