1

I needed to make a file in a repository non-readable and non-writable:

sudo chmod 101 file1.sh

when you list it it looks like this:

$ ls -la file1.sh
---x-----x 1 cardamom cardamom 13 Nov 16 16:52 file1.sh

git add will not work:

error: open("file1.sh"): Permission denied
error: unable to index file file1.sh
fatal: updating files failed

and adding it to .gitignore does not cause it to be ignored.
I don't really need to track it, but would be good to not have it pop up every time git status is typed in.

How does one either add it to the repo or tell git to ignore it?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
cardamom
  • 6,873
  • 11
  • 48
  • 102
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Nov 16 '18 at 20:10
  • https://stackoverflow.com/search?q=%5Bgitignore%5D+tracked+file – phd Nov 16 '18 at 20:10

2 Answers2

2

adding it to .gitignore won't work on a revision that is tracking it because the file is already tracked..... it will work on revisions after you delete it (and commit). Then, if you remove all permissions from the file, how do you expect git to be able to use it? It can't read it. So... if you don't mind having the file in history and then disappear, you could delete it (git rm --cached the-file), add it to .gitignore, then commit. For revisions starting with this revision the file won't show up to be added anymore. If you, however, chose to checkout to previous revisions, don't be surprised to see git behave funny because of the file being present on your working tree.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
2

How does one either add it to the repo or tell git to ignore it?


--assume-unchaged

Raise the --assume-unchaged flag on this file so it will stop tracking changes on this file

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.

Instead, this option sets/unsets the assume unchanged bit for the paths.

When the assume unchanged bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Weeks later it wouldn't let me checkout master. Turns out as well as update-index, they also needed to go in .gitignore, the command `git status --porcelain | grep '^??' | cut -c4- >> .gitignore` from [here](https://stackoverflow.com/a/15142010/4288043) was helpful. – cardamom Nov 28 '18 at 10:47