天天看点

git pull忽略指定文件,Git:忽略Commit和Pull中的特定文件

git pull忽略指定文件,Git:忽略Commit和Pull中的特定文件

I am "ignoring" our ConnectionString.config using update-index --assume-unchanged, as I change it often during development and is generated automatically by our build server anyway; however, when performing a Pull/Rebase the operation fails because it would overwrite it locally, forcing me to stash it and then restore it.

Is there a way to ignore a file both on commit and on pull? I just want Git to leave it be.

解决方案

If you want this to only happen on your local system, the local .git/info/exclude file should solve the problem.

To requote the answer from the above stack post:

Patterns which are specific to a particular repository but which do

not need to be shared with other related repositories (e.g., auxiliary

files that live inside the repository but are specific to one user's

workflow) should go into the $GIT_DIR/info/exclude file.

The .git/info/exclude file has the same format as any .gitignore file. Another option is to set core.excludesFile to the name of a file containing global patterns.

Note, if you already have unstaged changes you must run the following after editing your ignore-patterns:

git update-index --assume-unchanged [...]

Note on $GIT_DIR: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.