问题
I have staged two files file1.js
and file2.js
but I only want to commit file2.js
. How can I do this?
回答1:
Simplest solution: unstage the other (git status tells you how, git reset
).
回答2:
No need to unstage file1.js
(assuming you want to keep the changes in this file staged for the next commit), just enter
git commit file2.js
to only commit the changes recorded in file2.js
.
回答3:
What I did was
git reset file1.js
to unstage it. Then I commited file2.js
like i normally do.
回答4:
Reset/Unstage
the file that you don't want to commit using
git reset HEAD file1.js
After this you only have one staged file that will go into your commit.
来源:https://stackoverflow.com/questions/45913384/how-to-commit-a-single-staged-file