3

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

user3214546
  • 6,523
  • 13
  • 51
  • 98

4 Answers4

21

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.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • can i delete this file or do i need to keep it .git/info/exclude – user3214546 Feb 20 '15 at 02:19
  • I did that , it still detect them as modified – user3214546 Feb 20 '15 at 02:21
  • Not sure what exactly you did, but after `update-index`, my files do not detect as modified. `exclude`, as well as `.gitignore`, do not have any effect on files that are already in repository. – Amadan Feb 20 '15 at 02:28
  • thanks that worked , don't what wa sissue , i stashed the chnages and then again modified and then update the index. so does it mean that they will never be come as modified and i can chnage any time . or do i have to do it everytime i modify them – user3214546 Feb 20 '15 at 03:16
  • They will never be considered modified until you `--no-assume-unchanged` them. – Amadan Feb 20 '15 at 03:34
1

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

iFytil
  • 459
  • 3
  • 7
  • But does that mean that when i push to remote repo does those gets deleted from there or not. Because other members should keep working on at as normal. 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 – user3214546 Feb 20 '15 at 02:11
  • If you want the current state of these files to remain in the repository, but you want to ignore the changes made to those files then you will have to use unstage the deletion (using git reset HEAD file) those files and add them to the .gitignore. Or this: http://stackoverflow.com/questions/10755655/git-ignore-tracked-files – iFytil Feb 20 '15 at 02:18
0

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.

http://git-scm.com/docs

chrismillah
  • 3,704
  • 2
  • 14
  • 20
0

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'

wensveen
  • 783
  • 10
  • 20