Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

caching - Why git rm --cached not remove local ever tracked file but others

When untrack a file in the git repository, use git rm -r --cached .. This will not remove the ever tracked file in local storage, but when other developers fetch this commit with git pull, the ever tracked file will been removed on their machine storage.

You can reproduce it with:

  1. save current work. (Machine A)
git add .
git stash save "work position"
  1. create a new file and commit it.(Machine A)
echo hello>>file_not_to_track
git add .
git commit -m "add file file_not_to_track"
  1. pull from another machine(or another directory)(Machine B)
git pull

show files now

ls
file_not_to_track  README.md
  1. untrack the file.(Machine A)
echo file_not_to_track >> .gitignore
git rm -r --cached .
git add .
git commit -m "untrack file_not_to_track"
git push

show files now

ls
file_not_to_track  README.md
  1. fetch code(Machine B)
git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From example.com:my/example_project
   6525df1..f413f8b  master     -> origin/master
Updating 6525df1..f413f8b
Fast-forward
 .gitignore        | 1 +
 file_not_to_track | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 .gitignore
 delete mode 100644 file_not_to_track

show files now

ls
README.md

As it shows git rm -r --cached . remove ever tracked file on others repo but not in current repo.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

git rm --cached tracks a change of removing the file from git, but does not remove the local copy. Running ls locally will still show the local file, but if you pull from another machine, the change of removing that file will be applied, and the file removed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...