git update-index --assume-unchanged 忽略已被版本控制的文件

原文鏈接:https://my.oschina.net/xinxingegeya/blog/391432

Git 忽略已跟蹤文件的改動

git update-index --assume-unchanged

Git之本地忽略

這個分同種情況:

本地永久忽略,效果的gitignore一樣,只不過不適於寫到gitignore中而已,可以自己建立一個本地獨享的gitignore,然後git config --global core.excludesfile  文件的絕對路徑,也可以直接將本地要忽略的文件添加到.git/info/exclude中。

不過上述都是針對沒有跟蹤的文件來說的,如果文件已經被跟蹤了你如果在本地想要忽略它的改動,就不能使用以上的方法了。通俗地講比如一個編譯Android的腳本在其它電腦上都是使用的-j32來編譯的,但是你的電腦配置沒有別人的好,不能開到-j32,但是這個腳本是已經跟蹤過的,你修改了就會在每次的git status中看到。對於這種情況Git有一個忽略改動的方法:

$ git update-index --assume-unchanged /path/to/file       #忽略跟蹤

$ git update-index --no-assume-unchanged /path/to/file  #恢復跟蹤

如下所示,

Lenovo@LENOVO-PC /c/WorkSpace2/BodyBuilding (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

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:   BodyBuilding.iml

no changes added to commit (use "git add" and/or "git commit -a")

   modified:   BodyBuilding.iml,這個文件是處於modified狀態,現在要忽略他的改動,如下,

Lenovo@LENOVO-PC /c/WorkSpace2/BodyBuilding (master)
$ git update-index --assume-unchanged BodyBuilding.iml

Lenovo@LENOVO-PC /c/WorkSpace2/BodyBuilding (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

Lenovo@LENOVO-PC /c/WorkSpace2/BodyBuilding (master)
$

好了,完成了。這個文件的改動就不會被顯示出來。

=================END=================

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章