我有两个简明的问题:
- 如何跟踪文件但不暂存它们?
- 如何将文件从暂存区中取消暂存而不取消跟踪?
注意: 我知道可以进行初始提交以跟踪文件并从那里开始跟踪我的文件。但是是否可能具体实现我上面所问的内容?
我尝试使用 git add -N <expr>
,但它会跟踪该文件并将其添加到提交中:
PS C:\> git add -N fileA
PS C:\> git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: fileA
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README.md
# modified: composer.lock
# modified: fileA
#
如果我执行 git reset HEAD fileA
或者 git rm --cached fileA
,会取消暂存但同时也取消跟踪该文件。
这个命令 git rm fileA
建议我使用标志 -f 以物理方式删除该文件。
那么,只跟踪而不暂存,或者只取消暂存而不取消跟踪文件是可能的吗?
git ls-files
或git clean
这样的工具视为存储库的一部分,但在创建文件和将其包含在提交中之间的某个时刻,您可能希望使用这些工具。 - jayhendrengit add --help
的话说:“这对于显示使用git diff
的未暂存文件的内容以及使用git commit -a
提交它们等方面非常有用。” - jayhendren