我确实搜索了解决方案,但我相信我的情况与我读到的情况有些不同。
我在一个特定的分支上工作并犯了一个错误,以与分支主题无关的方式编辑了一个文件,现在希望这些更改不会进入提交。我不想丢失这些更改,因为稍后我会尝试以某种方式在另一个分支上提交它们。
我试过 git rm --cached
但后来我在我的 git status
中看到状态 deleted
- 文件会被删除吗 来自存储库?我不希望那样 - 我希望它与之前在我的工作分支上提交的内容保持不变。
最佳答案
如果您不暂存更改,它们将不会成为提交的一部分,如下所示:
git status
# On branch development
# 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: ResearchProposal.tex
这里,ResearchProposal.tex
有变化,但是不会被git commit
提交。
如果您在一个文件中有两组更改,一些您想要提交,一些您不想提交,请阅读this .
如果您在不想提交的文件上运行了git add
,您需要unstage
它:
git reset HEAD <file>
像这样:
$ git add ResearchProposal.tex
$ git status
# On branch development
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: ResearchProposal.tex
$ git reset HEAD ResearchProposal.tex
Unstaged changes after reset:
M ResearchProposal.tex
$ git status
# On branch development
# 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: ResearchProposal.tex
关于git - 使用 Git 提交时如何忽略对文件的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18508421/