Reputation: 12865
To make my project work locally I have to change one file. But this file has to be unchanged in the remote. How do I make git ignore the changes in this file when using git status
, git add
and git stash
command?
What I tried:
1.
git update-index --assume-unchanged filename
makes it work with 'git status' and 'git add', but 'git stash'+'git stash pop' restores the file to the original state, breaking my local setup.
2. I found this solution, but it changes remote as well, which I don't want to: https://www.codeblocq.com/2016/01/Untrack-files-already-added-to-git-repository-based-on-gitignore/
3.
adding the file to .git/info/exclude
doesn't work, since it is a file from the repository, not a new file.
Upvotes: 0
Views: 1547
Reputation: 4885
If you want to modify files locally but you don't want that Git manage these changes remotely, you can set the flag --skip-worktree
on a file which means the files should change locally, but not remotely. Any changes made and saved to this file will not be flagged as a change.
$ git update-index --skip-worktree path/to/your/skipping/file
To confirm, which files are skipped by Git, you can execute following command:
$ git ls-files -v | grep ^S
git ls-files
shows all files managed by Git-v
check the file being ignored--skip-worktree
is displayed with S
at line beginTo restore the file-skipping by Git, you need this command:
$ git update-index --no-skip-worktree path/to/your/skipping/file
Upvotes: 1
Reputation: 70
You can do this several ways:
Do a git status and then you will see what files are changed. after
that you can git add files separately.
Eg: git add [file name
(simply copy the path here when you get result from git status )]
Add to your file to git ignore file. This will un-track your changes on that mention file.
Upvotes: 0