git 写了挺多内容了突然发现自己居然是在 master 分支上写的 希望带着已经写的内容去开一个新分支 怎么做?

2020-07-09 20:58:09 +08:00
 Newyorkcity
谢谢!
3763 次点击
所在节点    git
19 条回复
Trim21
2020-07-09 21:00:31 +08:00
git checkout -b new-branch
THaGKI9
2020-07-09 21:01:30 +08:00
你已经 commit 了吗?

已经 commit 的话可以开新的 branch,然后 cherry pick

没 commit 的话直接开新的 branch 就好了,active change 会带过去的
across
2020-07-09 21:02:56 +08:00
退回到 master 之前的 A 点,建新分支,然后把之前的内容 Squash 过来....
gwy15
2020-07-09 21:03:38 +08:00
msg7086
2020-07-09 21:23:23 +08:00
给当前提交打上新的分支标记,然后把 master 回退回去。
如果还没提交的话可以直接新建并切换分支。
THaGKI9
2020-07-09 21:26:45 +08:00
@msg7086 号思路!
yongzhong
2020-07-09 21:27:59 +08:00
git stash push
git checkout -b new_branch
git stash pop
zhuweiyou
2020-07-10 01:31:01 +08:00
直接开,会带过去的。
KentY
2020-07-10 07:13:28 +08:00
看起来你是没 push, 但是 committed already.
如果没 committed, 很容易 co -b 就可以了
已经 committed 了有个省心的法:
1) checkout -b newbranch
2)然后在你本地把 master branch 删了
3)pull
完事
dubenshu
2020-07-10 08:23:10 +08:00
没 commit
$ git stash
$ git stash branch <new-branch>
已经 commit
$ git checkout -b <new-branch>
nutting
2020-07-10 08:26:19 +08:00
有没有人说说已经提交的话,ui 界面上是怎么操作
ericgui
2020-07-10 08:32:08 +08:00
git branch -m "new-branch-name"

git fetch origin master


basically, you'll need to reset the master branch.
hantsy
2020-07-10 09:05:49 +08:00
如果 Push 了的话,可以尝试(记不得了, 以前这种事,我也出现过。):

1, 直接在 Master 建立分支。

2, 然后 Master 上 Reset --Hard 上个点,commit, push 。一般 --hard 还是慎用。

不过这种应该要避免,首先从切换到一个好的 Shell 开始(各种 OhMyXXX 系列),一般图形工具都是会标注当前分支。
hantsy
2020-07-10 09:06:35 +08:00
@ericgui 重命名真没想到
as94boy
2020-07-10 09:33:01 +08:00
@KentY 这种简单粗暴的方法,一开始真的还没想到。但是很赞。
yinft
2020-07-10 13:27:50 +08:00
直接开就能带过去哦
yinft
2020-07-10 13:29:55 +08:00
git checkout -b
julyclyde
2020-07-10 14:29:32 +08:00
1 把自己这个“本地 master”push 到远程的新分支
2 然后把自己本地 master“倒回去”
EscYezi
2020-07-11 02:29:36 +08:00
@nutting #11 idea 的话可以 undo commit - create new branch and check out - commit&push

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

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

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

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

© 2021 V2EX