Reputation: 6831
I am working on project on my local machine. so i have different DB details, so i edited 2 files.
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: product/db.py
modified: product/prms.py
Now i don't want to commit it and want to ignore them locally so that no matter what i edit in those files they never gets pushed to remote repo
I tried put them in
.git/info/exclude
Then i did
git rm --cached <file>
but then system is removing them
Changes to be committed: (use "git reset HEAD ..." to unstage)
deleted: product/db.py
deleted: product/prms.py
But i don't want to remove them as well
How can i fix that
EDIT: I don't want push anything to remote repo regarding that. i just want to ignore edits to those file from my compuer perspective only. so that when i got to office and then i make chnage in that file then it should work as normal. but from my home any edits should be invisible to git
Upvotes: 3
Views: 10069
Reputation: 884
Another option is to use: git update-index --skip-worktree path/to/file
There are a few practical and philosophical differences. Mainly, use skip-worktree
when modifying the file is expected. Use assume-unchanged
when git can safely assume the file is unchanged and optimize its behavior accordingly.
A very thorough explanation is given here: Git - Difference Between 'assume-unchanged' and 'skip-worktree'
Upvotes: 1
Reputation: 3914
If you want to omit files from a commit, you should use the 'stash' method.
git stash --keep-index
This will stash all your uncommitted changes -- you can always un-stash them later. Now you can keep working without those files getting pushed to your remote repository..
Keep in mind that you can pull and continue to collaborate while still keeping these changes stashed.
If you use something like bitbucket, you could have gone to the 'source' of the branch that you were working with and gotten the code from your last commit and fixed these two files.
Upvotes: 0
Reputation: 198314
Approach 1:
Do not commit files that should differ per developer. All of my config files (e.g. config.yaml
) are in .gitignore
; for each, I will have another file, (e.g. config.yaml.template
), that would show the developers what they need to look like, which I would only edit when the structure changes.
Approach 2:
git update-index --assume-unchanged product/db.py product/prms.py
will let you change the files, and git
will not commit them. If you do wish to commit them again, rerun it with --no-assume-unchanged
.
Upvotes: 23
Reputation: 459
There doesn't seem to a be a problem. Git is notifying you that those files used to be in the repository and are being deleted from the repository.
This is exactly what you want. The fact that git removes them from the repository does not necessarily mean that you are deleting them from your local file system. In fact, since you've used
git rm --cached
they should still be in your file system.
If at any point there was a commit that was pushed onto your branch which added these files, you will have to push another commit which will be removing these files.
If these files follow a pattern, you might find it useful to add them to the .gitignore. For instance, it's very commit to add
*.class
/bin
in your .gitignore because you tend not to want to push class files (if you're doing Java/Scala) or binaries which tend to live in /bin
Upvotes: 1