Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

version control - Git ignore files being tracked WITHOUT DELETING THEM

I'm having some trouble understanding basic git concepts :/

I'm testing on my local Windows machine before trying some things on my git-controlled site.

I have:

gittesting/repo1:
    file.txt
    ignoreme:
        ignore.txt

and

gittesting/repo2
    file.txt
    ignoreme:
        ignore.txt

Repo2 is a copy of repo1, and ignoreme is already being tracked. The ignore.txt file becomes changed in repo2, but I want to stop tracking it and for git to completely ignore it. The problem is that if I create a .gitignore file and add ignoreme, it's too late because it's already being tracked, so I would have to do git rm --cached ignore, but then it's marked as deleted and if I pulled the commit to repo1, the directory would be deleted instead of being left alone..

To sum it up:

  1. The ignore.txt have different content between the two repos.
  2. I want the ignore.txt contents to remain as they are and be completely ignored by git

I've looked online, asked in the IRC, and looked at the very related questions, but can't find a way to do this. I know the example seems trivial, but it's exactly what I need to do on my site, where the directory is Forum/cache instead.


edit:

This is a bit of a hack and I'd prefer a better answer, but I ended up doing:

cd repo2
echo "ignoreme" > .gitignore
echo "ignoreme/*" > .gitignore
git rm --cache -r ignoreme
git commit -m "Should ignore now"
cd ../repo1
mv ignoreme ignoreme2
git pull ../repo2
mv ignoreme2 ignoreme
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this

git update-index --assume-unchanged ignoreme/ignore.txt

Git will ignore any future changes to this file without changing the repository. To start tracking changes again, use

git update-index --no-assume-unchanged ignoreme/ignore.txt

Note that this only takes effect for the current working copy, so you would need to do this each time you clone the repository.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...