Can git split a commit that was upstream using a revert?

Sukima

I have a repo that is pushed to a remote and downloaded by others. Within the history is a bug introduced by a commit I made. Embarrassingly that commit it unwieldy (too much logic in one commit). Aside from going back in time and whacking my past self with a wet noodle the proper thing to do would be an interactive rebase to split the commit into several.

Sadly this has already been pushed and cloned by others (who would be very unpleased if I rebased from underneath them). So I thought I could branch, revert commit, cherry-pick commit, interactive rebase, then merge. Is this the best option or am I missing something?

Can I split a published commit by reverting then splitting?

A--B--C--D--E--F (master origin/master)
      ^- WTF commit


A--B--C--D--E--F-------------------M (master origin/master)
                \                 /
                 G--C1--C2--C3--C4   (split-and-fix-branch)
                 ^- revert commit C
Sukima

So my instinct is correct. The following lays out how to split/edit a commit that has already been pushed and pulled.

EDIT: Modified procedure with suggestions from comments.

If this is local only use get rebase -i instead.

A--B--C--D--E--F (master origin/master)
      ^- WTF Commit

$ git checkout -b split-n-fix C

A--B--C--D--E--F (master origin/master)
      ^ (split-n-fix)

$ git revert C

A--B--C--D--E--F (master origin/master)
       \
        R (split-n-fix)

$ git cherry-pick --no-commit C

A--B--C--D--E--F (master origin/master)
       \
        R--(dirty) (split-n-fix)

$ git add -p
$ git commit
(repeat till finished)

A--B--C--D--E--F (master origin/master)
       \
        R--C1--C2--C3--C4 (split-n-fix)

$ git checkout master
$ git merge split-n-fix
$ git branch -d split-n-fix

A--B--C--D--E--F----------M (master origin/master)
       \                 /
        R--C1--C2--C3--C4

$ git push

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How can I stop myself from using 'git commit -a'?

来自分类Dev

Git workflow: submitting pull requests to upstream and using the commits in the meantime

来自分类Dev

什么是git revert --quit?

来自分类Dev

在不打开编辑器的情况下将字符串追加到git revert commit消息

来自分类Dev

How can I use git revert to restore all mistakenly deleted files?

来自分类Dev

git revert reset --hard命令

来自分类Dev

澄清git revert和rebase

来自分类Dev

Visual Studio 2015 Preview - Can't commit with Git

来自分类Dev

git revert-无阶段提交

来自分类Dev

git revert -m 1后无法合并

来自分类Dev

如何阅读git revert的手册页?

来自分类Dev

合并分支后出现“ git revert”问题

来自分类Dev

git revert 到底是做什么的?

来自分类Dev

启动后继续/中止 git revert

来自分类Dev

Git revert 进入 VIM 编辑器

来自分类Dev

Git的@ {upstream}和@ {push}有何区别?

来自分类Dev

是git add。; git commit -a等效于git add -A。git commit -a?

来自分类Dev

git commit打破时区

来自分类Dev

git commit忽略行尾

来自分类Dev

从git commit修剪URL

来自分类Dev

在git commit中警告

来自分类Dev

丢失了git commit

来自分类Dev

git reset和git revert有什么区别?

来自分类Dev

Can I avoid calculating same elements when using split() in Halide?

来自分类Dev

Understanding when to use git commit -m and git commit -am

来自分类Dev

了解何时使用git commit -m和git commit -am

来自分类Dev

Pre Commit hook git error

来自分类Dev

并发git checkout / add / commit

来自分类Dev

git commit引发错误“ [<-”