git
› Pro Git
› Atlassian Git Tutorial
› Pro Git 简体中文翻译
› GitX
lbfeng
V2EX  ›  git

git 退回到几个 commit 之前,并且保存现有代码

  •  
  •   lbfeng · Apr 13, 2016 · 11692 views
    This topic created in 3861 days ago, the information mentioned may be changed or developed.

    新 push 了一个功能,后来发现暂时不能 merge 。现在需要退回到几个 commit 之前,但是不能丢掉这几个 commit ,之后应该还能用到。用 revert 还是 reset?

    18 replies  •  2016-04-13 14:21:59 +08:00
    cevincheung
    cevincheung
    Apr 13, 2016
    1
    开分支
    cevincheung
    cevincheung
    Apr 13, 2016
    2
    先备份现在代码,回滚版本。开分支,应用新代码。啥时候 merge 啥时候再合并本地两个分支。
    lbfeng
    lbfeng
    OP
    Apr 13, 2016
    3
    @cevincheung thx. checkout 之前的 commit, 转到新的 branch 。
    clino
    clino
    Apr 13, 2016 via Android
    4
    将代码提交到一个临时分支 之后随便折腾
    RoshanWu
    RoshanWu
    Apr 13, 2016 via iPhone
    5
    git reset 提交点
    git stash
    git checkout -b 新分支
    开发新功能
    在任意时间节点想应用回原先修改部分: git stash pop
    如要放弃原先修改部分: git stash drop
    rwecho
    rwecho
    Apr 13, 2016
    6
    stash
    v1024
    v1024
    Apr 13, 2016
    7
    用 SourceTree 的话,可以在需要回退到的 commit 上点分支,就会从那个位置新建一个分支,现在的代码还在当前分支上就好。
    yxzblue
    yxzblue
    Apr 13, 2016
    8
    git reset --soft
    restran
    restran
    Apr 13, 2016
    9
    利用 git reflog 可以找到所有操作的提交点,即便是直接 git reset 到提交点,这之间的所有 commit 也都还是能回退回去的。可以看看聊雪峰的 Git 教程,版本回退那一章。如果你用 TortoiseGit 可以看看 http://www.restran.net/2016/02/22/git-recovery/
    msg7086
    msg7086
    Apr 13, 2016
    10
    当前提交上新建 Feature 分支,然后把主干分支 reset 回去就好了。
    flowfire
    flowfire
    Apr 13, 2016
    11
    直接 reset 就好。。。。因为即使 reset 了。现有版本并没有被删除。。。
    bombless
    bombless
    Apr 13, 2016 via Android
    12
    git branch 备份分支名
    git reset --hard 之前的某个提交
    git push -f
    VicYu
    VicYu
    Apr 13, 2016
    13
    git stash
    git reset
    jsonline
    jsonline
    Apr 13, 2016
    14
    branch 吧
    yoa1q7y
    yoa1q7y
    Apr 13, 2016
    15
    好多人真的不会用 git...
    yoa1q7y
    yoa1q7y
    Apr 13, 2016
    16
    8 楼正确答案
    wweir
    wweir
    Apr 13, 2016
    17
    git rebase old_commit
    jackisnotspirate
    jackisnotspirate
    Apr 13, 2016
    18
    git rebase
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1563 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 12:24 · PVG 20:24 · LAX 04:24 · JFK 07:24
    ♥ Do have faith in what you're doing.