问题
I need to work on file.txt
locally and in Git, with different content. I want Git not to tell me that there have been changes to that file.
Is this possible?
回答1:
Actually, you want --skip-worktree
, not --assume-unchanged
. Here's a good explanation why.
So git update-index --skip-worktree file.txt
TLDR; --assume-unchanged
is for performance, for files that won't change (like SDKs); --skip-worktree
is for files that exist on remote but that you want to make local (untracked) changes to.
回答2:
Maybe you want to "pretend" that the file hasn't changed when actually it did? You can do that like this:
git update-index --assume-unchanged file.txt
To undo this later:
git update-index --no-assume-unchanged file.txt
To view a list of files that are marked this way:
git ls-files -v | grep '^[a-z]'
UPDATE
As comments have pointed out, this is most probably NOT what you want to do. A better answer has been posted by @Tom Auger, use that instead.
回答3:
If modifying the .gitignore
file is not an option (because it is checked into git itself), consider using .git/info/exclude
.
回答4:
Can you not use .gitignore file?
回答5:
All you need is to click the more
button in sourcetree just at the right hand side of the filename, in the unstaged files section. Click ignore
and make source tree perform your desired action for that file or all the files with the same type.
回答6:
SOURCETREE Terminal codes
Add ignore file:
git update-index --skip-worktree index.php
Extract ignore file:
git update-index --no-skip-worktree index.php
List ignore files:
git ls-files . --ignored --exclude-standard --others
回答7:
In Eclipse Luna, this can be done [with EGit plugin I think] by doing this: right-click file -> Team -> Advanced -> Assume unchanged
来源:https://stackoverflow.com/questions/20525055/how-to-ignore-existing-file-in-git