1.修改文件A,commit并push到远程仓库
2.修改文件B,commit,也push到了远程
3.现在A文件的修改错误了,需要回滚到之前的版本,但是文件B的修改需要保存下来,请问现在应该如何操作?
如果用git reset --hard命令回滚到A修改的版本号,那么B的修改也被丢弃了
巴扎黑2017-05-02 09:39:50
$ mkdir test
$ cd test
$ git init
$ echo aaaa>a.txt
$ echo bbbb>b.txt
$ git commit -a -m "init two files"
[master (root-commit) 2ca34b8] init
...
$ echo update>a.txt
$ git commit -a -m "update file a"
[master **e216f56**] update file a
...
$ echo update>b.txt
$ git commit -a -m "update file b"
[master 6906147] update file b
...
$ git revert **e216f56**
unix2dos: converting file f:/test/.git/COMMIT_EDITMSG...
dos2unix: converting file f:/test/.git/COMMIT_EDITMSG...
[master 2a9c653] Revert "update file a"
...
仅有的幸福2017-05-02 09:39:50
You won’t lose it by doing this, we all do this..
git reset --hard command rolls back to the version number modified by A
git pull --rebase origin branch number Pull down the code of B to see if there is any conflict , git push after conflict resolution
..
给我你的怀抱2017-05-02 09:39:50
git reset --soft HEAD@{id}, this will withdraw the submission, but the modifications in the workspace will not disappear, then correct the wrong modifications, submit and push to the remote end
我想大声告诉你2017-05-02 09:39:50
In this case, I usually check the log directly and restore file A to ensure that file B is complete
大家讲道理2017-05-02 09:39:50
Can’t you just modify the wrong ones and then submit them once to overwrite them?
伊谢尔伦2017-05-02 09:39:50
Don’t use git reset
,如果有人已经 pull 了这些 commit,会很麻烦
这种情况下应该用 git revert
on an already submitted commit on the public branch, it will generate a separate commit
ringa_lee2017-05-02 09:39:50
git rebase -i HEAD^^^
用默认编辑器打开一个文档,修个A
那次提交前面改成drop
或简写为d
Save.
The submission will be automatically discarded (if there is a conflict, you have to resolve the conflict yourself)
PHP中文网2017-05-02 09:39:50
git log View the commitId of A B before A
git reset --hard A's previous commitId
git cherry-pick B’s commitId
This function is called the checkout function, and you can get the modifications submitted at a certain time
伊谢尔伦2017-05-02 09:39:50
You can only revert, not reset. Any commit that has been pushed to the remote cannot be reset or commit --amend. This will destroy other people's version history.
For information about revert, you can read this article of mine: /a/11...