git reset用法二 替換檔案

來源:互聯網
上載者:User

git reset的第二種用法不是用於重設引用的,而是為了能夠將某個曆史版本中的檔案拿出來,替換當前staging中的同名檔案。

這個也更加常用。

比如

git reset 

就是用倉庫中目前的版本的檔案(位於.git/objects目錄下)替換掉staging中的檔案。相當於撤銷上一次git add的作用。

比如我們在x檔案中添加一些內容,然後用下面的命令:

$ git add -u$ git resetUnstaged changes after reset:Mx$ git commit -m'change x file'# On branch master# Your branch is ahead of 'origin/master' by 1 commit.## Changes not staged for commit:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##modified:   x#no changes added to commit (use "git add" and/or "git commit -a")

git reset撤銷了之前對staging地區的操作,因此git commit就提示staging地區沒有什麼需要提交的。

git reset HEAD 命令和 git reset相同。

還可更加精確的指定檔案名稱,只對某個檔案執行撤銷操作。

$ git reset -- ~/work/189/appengine/x

注意中間用--間隔開,後面可以輸入檔案的完整路徑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.