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

Categories

I have added a file named "file1.txt" to a Git repository.

(我已将名为"file1.txt"的文件添加到Git存储库中。)

After that, I committed it, added a couple of directories called dir1 and dir2 , and committed them to the Git repository.

(之后,我提交了它,添加了几个名为dir1dir2的目录,并将它们提交给Git存储库。)

Now the current repository has "file1.txt" , dir1 , and dir2 .

(现在,当前存储库具有"file1.txt"dir1dir2 。)

How can I delete "file1.txt" without affecting others, like dir1 and dir2 ?

(如何在不影响其他内容的情况下删除"file1.txt" ,例如dir1dir2 ?)

  ask by webminal.org translate from so

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

1 Answer

Use git rm :

(使用git rm :)

git rm file1.txt
git commit -m "remove file1.txt"

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

(但是,如果您只想从Git存储库中删除文件而不是从文件系统中删除它,请使用:)

git rm --cached file1.txt
git commit -m "remove file1.txt"

And to push changes to remote repo

(并将更改推送到远程仓库)

git push origin branch_name  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...