Git Include file, but its changes are not tracked

I would like to include the source file (if it was delivered when someone cloned the repository) in my repository, but it was ignored by default.

git update-index --assume-unchanged ... does not work as it only applies to the local index. I want all users to ignore this file by default.

.gitignore does not work, because if I track the file through git add -f .. , then its changes are tracked.

I am trying to achieve what happens if I svn add edited a file, then svn:ignore edited it.

EDIT:

It seems like this is not possible in Git, and I changed the organization of the source file and the assembly based on this old Subversion behavior.

Examples:

 $ git clone git@git :gsmith/sandbox.git snip... $ cd sandbox/ $ ls -a . .. .git .gitignore gitignored tracked $ cat .gitignore gitignored $ echo foo >> gitignored $ git status # On branch master # 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: gitignored # no changes added to commit (use "git add" and/or "git commit -a") 

I would like this file to be ignored.

 $ git reset --hard HEAD HEAD is now at 34b1f3d initial setup $ git rm gitignored rm 'gitignored' $ git commit -m "test" [master cd8199d] test 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 gitignored $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) $ ls -a . .. .git .gitignore tracked $ echo foo >> gitignored $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) 

Now it is ignored. However, someone who clones the repository will not receive the gitignored content.

+6
source share
2 answers
  • Add the file to your repo specific .gitignore .
  • If it is already being monitored (maybe your case), just git rm --cached myfile .

I hope you want it. If not, you can take a look at this .

0
source

Paraphrase the title: you want to track the file, but its changes are not tracked. This is as many contradictions as it seems. Presumably, you have a file that changes locally, which does not make sense to other users of the repository, but also contains content that everyone needs. The answer, of course, is not that. There are two main options:

  • Separate the file. One part is the β€œlocal” one, which does not need to be monitored, and the other part is the main / general one, containing everything that everyone needs and will usually not change. You should create an empty / template local file automatically, if necessary build / deploy / run time.

  • Expand the file as a template, and then make a copy to use it. You will make a copy automatically, if necessary to build / deploy / execute.

In any case, the question is not, "how can I tell Git not to track this file, I just told it to track?" but "why am I trying to track as well as track the same content?"

0
source

Source: https://habr.com/ru/post/902799/


All Articles