Ignore files from git diff or git state using shell

I would like to ignore files when running git diff or git status from the shell using a simple file template.

I can "apply diff or status only to files that match this pattern," but I don't know how to say "ignore files that match this pattern."

What I'm doing right now to apply commands to a subset of files is:

 $ git status */models.py $ git diff */models.py 

I would like to be able to do this from the command line without specifying Git settings. Is it possible?

+4
source share
3 answers

There is no standard way to do this without a command line flag.

If the changes you want to exclude are good changes that you ultimately want to commit, then I suggest adding them to the staging area. That way you can do git diff and they will not appear.

On the other hand, if the changes you want to exclude are shitty experimental changes that you probably would not want to commit, then it can be dangerous to add them to the intermediate area, as they are easily transferred by mistake. In this case, it is better to add all the good changes to the staging area and view their diff with git diff --cached .

Regarding the exception to the status, I recommend just grep -v :

 git status | grep -v stuff-to-exclude 
+2
source

You can use git ls-files , grep and xargs like:

 git ls-files | grep -v models.py | xargs git diff 
+1
source

As shown in " git update-index --assume-unchanged in directory ", you can test and play with the command:

  git update-index --assume-unchanged 

Thus, git diff or git status should ignore the files you just flagged as "immutable."

Note: to return this: git update-index --no-assume-unchanged .

(if this does not work fully, try git update-index --skip-worktree ).

0
source

Source: https://habr.com/ru/post/1489748/


All Articles