How to commit a single staged file?

断了今生、忘了曾经 提交于 2019-12-10 18:01:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!