git 如何回滚
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:37:50
0
10
692

场景:

  • 1.修改文件A,commit并push到远程仓库

  • 2.修改文件B,commit,也push到了远程

  • 3.现在A文件的修改错误了,需要回滚到之前的版本,但是文件B的修改需要保存下来,请问现在应该如何操作?

如果用git reset --hard命令回滚到A修改的版本号,那么B的修改也被丢弃了

过去多啦不再A梦
过去多啦不再A梦

reply all(10)
巴扎黑
$ 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"
...
PHPzhong

git revert (version number)

仅有的幸福

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
..

给我你的怀抱

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

我想大声告诉你

In this case, I usually check the log directly and restore file A to ensure that file B is complete

大家讲道理

Can’t you just modify the wrong ones and then submit them once to overwrite them?

伊谢尔伦

Don’t use git reset,如果有人已经 pull 了这些 commit,会很麻烦
这种情况下应该用 git revert on an already submitted commit on the public branch, it will generate a separate commit

左手右手慢动作

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)

Ty80
  1. git log View the commitId of A B before A

  2. git reset --hard A's previous commitId

  3. git cherry-pick B’s commitId

This function is called the checkout function, and you can get the modifications submitted at a certain time

伊谢尔伦

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...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!