2

I know we have lot of discussions on this out here but those aren't solving my issue. So placing my question here.

I want to untrack some files from being shown as modified while doing git status, and I tried different options as explained here

ex. I want to untrack test.txt file and I tried like these:

git update-index --skip-worktree test.txt

Immediately, when I do git status, still it is showing as modified. Is there something wrong here? Also, I tried adding this to .git/info/exclude file but no luck. Can anyone please throw some ideas here?

Lumito
  • 490
  • 6
  • 20
Shan C
  • 87
  • 1
  • 2
  • 11
  • Tracked file, and you want to remove it? Would `git rm —cached` do? https://stackoverflow.com/q/33428702/989920 – evolutionxbox Mar 01 '18 at 23:46
  • I think you are mixing up concepts. Untracking a file means removing it from the repo. To do that you'd `git rm --cached` and then commit the change. This means that the file will be **removed** for other developers who use the same repo (assuming you pushed the commit). After having untracked the file, if you do not want it to show up in `git status`, you can add it to the `.gitignore` file. If you instead want `test.txt` file to be kept in the repo, but want to make modifications to it without those showing up in `git status`, that's when you can use the `skip-worktree` command... – Alderath Mar 02 '18 at 09:06
  • But you should **not** both untrack the file **and** issue the `skip-worktree` command that you mention in your question. – Alderath Mar 02 '18 at 09:07
  • _"Immediately, when I do git status, still it is showing as modified."_ - that should not happen, unless the file is already staged - is it? – 1615903 Mar 02 '18 at 09:24
  • @Alderath, yes you're correct. Exactly I want skip-worktree as I want to setup some personal .gitignore kind here. If I add it in .gitignore, it is not showing up but it would affect all the developers when I push it. I don't want that. I just want to exclude some files from showing up on git status in my machine only. – Shan C Mar 02 '18 at 13:56
  • @evolutionxbox - git rm -cached is removing the file itself and it will remove from repo too if I push the changes. So, I chose skiptree as I am in need of that kind. – Shan C Mar 02 '18 at 14:00
  • `—cached` should stop the file from being deleted. – evolutionxbox Mar 02 '18 at 14:31
  • @evolutionxbox, Thanks for your time. Will try again and see. – Shan C Mar 02 '18 at 15:26

2 Answers2

1

The files must have already been in the staging area before you flagged them. You must first remove them from the staging area to exclude them.

First, run 'git reset' to remove the files from staging.

Then, run the 'git update-index' command to flag the files as Skip-Worktree/Assume-Unchanged.

Satish Kumar
  • 203
  • 3
  • 8
0

Simply remove it from git status would be:

git reset -- afileBeginModified

But untracking completely would be a combination of:

git rm --cached -- afile_I_Dont_want_to_see_ever
echo afile_I_Dont_want_to_see_ever > .gitignore
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • git rm -cached is removing the file itself and it will remove from repo too if I push the changes. I am in need of something that will exclude a file from showing up in status irrespective of that file already there in repo or not. Thanks. – Shan C Mar 02 '18 at 14:39
  • @SCSVEL Did you try assume-unchanged? (as I documented in https://stackoverflow.com/a/23806990/6309) – VonC Mar 02 '18 at 14:40
  • yeah. I did try assume-unchanged too but no luck. – Shan C Mar 02 '18 at 15:09
  • @SCSVEL Then read http://xyproblem.info/, and adopt a different aproach. For instance: https://stackoverflow.com/a/48449663/6309 – VonC Mar 02 '18 at 15:11
  • Thanks for your time. I will try again from start and see with different approach. – Shan C Mar 02 '18 at 15:27