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
434 views
in Technique[技术] by (71.8m points)

filesystems - Delete files from git index when they are already deleted from fs

I have a bunch of files deleted from the fs and listed as deleted in git status.

How can I stage this changes faster then running git rm for each file?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You can do this with:

git ls-files --deleted -z | xargs -0 git rm

Whenever this question is asked, people suggest git add -u, but the problem with that answer is that it also stages other modifications in your working copy, not just deletions. That might be OK in many situations, but if you want to just stage the deletion of files that have been deleted from the working copy, the suggestion I've made is more precise.

There's actually a section of the git rm documentation that discusses how to do what you want - I believe that the command suggested in the "Other ways" section is equivalent to what I've suggested here.


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

...