假设修改了1.js,2.js,3.js,现在想同时提交1.js和2.js,结果命令输成:
git commit -m "xxx" 1.js 3.js |
2.js没commit,反而是把3.js commit了,现在想在push前撤销这次commit而且同时不能丢掉这三个文件的修改。
操作如下:
git reset --soft HEAD~1 |
看看结果:
git status On branch develop Your branch and 'origin/develop' have diverged, and have 1 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours) Changes to be committed: (use "git reset HEAD..." to unstage) modified: 1.js modified: 3.js Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout --..." to discard changes in working directory) modified: 2.js |
这时可以再次提交1.js和2.js:
git commit -m "xxx" 1.js 2.js |
再看status:
git status On branch develop Your branch and 'origin/develop' have diverged, and have 2 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours) Changes to be committed: (use "git reset HEAD..." to unstage) modified: 3.js |
此时3.js还在暂存区,git status有提示将3.js移出暂存区的命令:
git reset HEAD 3.js |
最后:
git status On branch develop Your branch and 'origin/develop' have diverged, and have 2 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours) Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout --..." to discard changes in working directory) modified: 3.js |
一切正常了。
http://blog.csdn.net/hudashi/article/details/7664464