Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ignored file to repo but don't track afterwards

Tags:

git

I have a "parameters" file in a repo, which I've added to .gitignore so it is not being tracked.

I need to push it once so that it shows in the repo, but making sure it is not tracked. This is because I'll keep modifying it (since it stores input parameters) and I only want the default version showing in the repo.

If I git add --force my_params.dat the file is pushed, but then it keeps being tracked, which I do not want.

What are the correct steps to achieve this? I tend to avoid using git update-index --assume-unchanged FILE_NAME because I feel it obscures the tracking process, but I'm not strictly opposed to using it.


If I had to use the answers in the question How to make Git "forget" about a file that was tracked but is now in .gitignore?, I'd need to:

  1. remove parameters file from .gitignore

  2. push file and changed .gitignore

  3. re-add parameters file to .gitignore and push

  4. remove all tracked files with git rm --cached -r .

  5. re-add all files with git add . and push them

This doesn't work because it deletes the parameters file from the repo when I push . That's not what I need.

like image 519
Gabriel Avatar asked Mar 03 '17 12:03

Gabriel


2 Answers

I don't think it is intended nor possible via git.

I would recommend to hierarchically load the paraemter files. You either load parameters.file or, if not existing, paramters.default.file. The paramters.default.file is kept in git, whereas the parameters.file is ignored.

Users who want to adapt the parameters need to create a file parameters.file for that purpose (alternatively you can automate the process during some make/setup process).

like image 198
Marcus Avatar answered Jan 11 '23 03:01

Marcus


It looks like there's been a new feature added to support this kind of scenario

git update-index --skip-worktree <file>

Source: https://stackoverflow.com/a/20241145/2436737
More info: Git - Difference Between 'assume-unchanged' and 'skip-worktree'

like image 23
farlee2121 Avatar answered Jan 11 '23 02:01

farlee2121