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

2016-04-13 05:28:24 +08:00
 lbfeng

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

10533 次点击
所在节点    git
18 条回复
cevincheung
2016-04-13 05:45:21 +08:00
开分支
cevincheung
2016-04-13 05:46:06 +08:00
先备份现在代码,回滚版本。开分支,应用新代码。啥时候 merge 啥时候再合并本地两个分支。
lbfeng
2016-04-13 06:08:47 +08:00
@cevincheung thx. checkout 之前的 commit, 转到新的 branch 。
clino
2016-04-13 07:21:41 +08:00
将代码提交到一个临时分支 之后随便折腾
RoshanWu
2016-04-13 07:48:17 +08:00
git reset 提交点
git stash
git checkout -b 新分支
开发新功能
在任意时间节点想应用回原先修改部分: git stash pop
如要放弃原先修改部分: git stash drop
rwecho
2016-04-13 08:19:44 +08:00
stash
v1024
2016-04-13 08:27:59 +08:00
用 SourceTree 的话,可以在需要回退到的 commit 上点分支,就会从那个位置新建一个分支,现在的代码还在当前分支上就好。
yxzblue
2016-04-13 08:28:54 +08:00
git reset --soft
restran
2016-04-13 08:50:12 +08:00
利用 git reflog 可以找到所有操作的提交点,即便是直接 git reset 到提交点,这之间的所有 commit 也都还是能回退回去的。可以看看聊雪峰的 Git 教程,版本回退那一章。如果你用 TortoiseGit 可以看看 http://www.restran.net/2016/02/22/git-recovery/
msg7086
2016-04-13 09:28:31 +08:00
当前提交上新建 Feature 分支,然后把主干分支 reset 回去就好了。
flowfire
2016-04-13 09:33:14 +08:00
直接 reset 就好。。。。因为即使 reset 了。现有版本并没有被删除。。。
bombless
2016-04-13 10:45:13 +08:00
git branch 备份分支名
git reset --hard 之前的某个提交
git push -f
VicYu
2016-04-13 11:01:33 +08:00
git stash
git reset
jsonline
2016-04-13 11:10:03 +08:00
branch 吧
yoa1q7y
2016-04-13 11:52:00 +08:00
好多人真的不会用 git...
yoa1q7y
2016-04-13 11:52:49 +08:00
8 楼正确答案
wweir
2016-04-13 14:19:57 +08:00
git rebase old_commit
jackisnotspirate
2016-04-13 14:21:59 +08:00
git rebase

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/270602

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX