我在Git仓库中添加了一个名为"file1.txt"
的文件。之后,我提交了它,添加了几个名为dir1
和dir2
的目录,并将它们提交到Git仓库。
现在仓库里有"file1.txt"
, dir1
, 和dir2
。我怎样才能删除"file1.txt"
而不影响其他的,如dir1
和dir2
?
使用[git rm
](https://git-scm.com/docs/git-rm)。
git rm file1.txt
git commit -m "remove file1.txt"
但如果你只想把文件从 Git 仓库中删除,而不是从文件系统中删除,请使用。
git rm --cached file1.txt
git commit -m "remove file1.txt"
而要推送修改到远程仓库
git push origin branch_name
更普遍的是,git help
至少可以帮助解决这样的简单问题。
zhasper@berens:/media/Kindle/documents$ git help
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]
The most commonly used git commands are:
add Add file contents to the index
:
rm Remove files from the working tree and from the index