Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programming
  3. Is there a way to rewind the git rebase state?

Is there a way to rewind the git rebase state?

Scheduled Pinned Locked Moved Programming
programming
25 Posts 10 Posters 82 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q This user is from outside of this forum
    Q This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #1

    Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
    I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
    So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

    thenextguy@lemmy.worldT 2xsaiko@discuss.tchncs.de2 kissaki@programming.devK B M 8 Replies Last reply
    1
    0
    • System shared this topic on
    • Q [email protected]

      Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
      I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
      So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

      thenextguy@lemmy.worldT This user is from outside of this forum
      thenextguy@lemmy.worldT This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #2

      Pretty sure you have to abort and start over.

      1 Reply Last reply
      0
      • Q [email protected]

        Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
        I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
        So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

        2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
        2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #3

        You could abort the rebase, then move back to the commit you want to using the reflog and remove the entries you skipped from the rebase todo.

        I also recommend checking out jj (https://github.com/jj-vcs/jj), it makes big rebases a lot more pleasant because of its conflict model and because you can always undo operations like this.

        Q 1 Reply Last reply
        0
        • 2xsaiko@discuss.tchncs.de2 [email protected]

          You could abort the rebase, then move back to the commit you want to using the reflog and remove the entries you skipped from the rebase todo.

          I also recommend checking out jj (https://github.com/jj-vcs/jj), it makes big rebases a lot more pleasant because of its conflict model and because you can always undo operations like this.

          Q This user is from outside of this forum
          Q This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #4

          You could abort the rebase, then move back to the commit you want to using the reflog and remove the entries you skipped from the rebase todo.

          Would this bring me back to the rebasing process so I don't lose the progress?

          Interesting mention of jj, never heard of it before! It says it can use Git as backend, so that means I could do these kinds of operations easily without stringing several commands together on the repositories I'm already working on without changing them?

          2xsaiko@discuss.tchncs.de2 1 Reply Last reply
          0
          • Q [email protected]

            Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
            I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
            So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

            kissaki@programming.devK This user is from outside of this forum
            kissaki@programming.devK This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #5

            You can reset to the previous commit, then pick the commits you want in the order you want, and then continue the rebase.

            1 Reply Last reply
            0
            • Q [email protected]

              Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
              I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
              So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

              B This user is from outside of this forum
              B This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #6

              You can always make patchfiles and apply those.

              Instead of rebasing, consider a new brach and then cherry picking commits.

              1 Reply Last reply
              0
              • Q [email protected]

                Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
                I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
                So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

                M This user is from outside of this forum
                M This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #7

                Whatever you do, familiarize yourself with git reflog. It contains all the commits, regardless of your current branch state. Even ones you might think you lost. (For about two weeks until it cleans itself up.)

                In your shoes, I usually abort the rebase and start a new branch and cherry-pick the commits I need.

                It takes awhile, but it's reliable.

                Source: In my overconfidence, I screw up my local git state pretty often.

                Q 1 Reply Last reply
                0
                • Q [email protected]

                  You could abort the rebase, then move back to the commit you want to using the reflog and remove the entries you skipped from the rebase todo.

                  Would this bring me back to the rebasing process so I don't lose the progress?

                  Interesting mention of jj, never heard of it before! It says it can use Git as backend, so that means I could do these kinds of operations easily without stringing several commands together on the repositories I'm already working on without changing them?

                  2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
                  2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #8

                  Right, you need to first restart the rebase, then git reset --hard to whatever commit from the reflog, then edit the todo list. Might need git rebase --skip too to make it read the next entry. I haven't done this myself yet fwiw.

                  It says it can use Git as backend, so that means I could do these kinds of operations easily without stringing several commands together on the repositories I’m already working on without changing them?

                  You can either clone a repo fresh or have it take over an existing git repo that you already have cloned locally. Normally you can only use its own commands, but you can create a repo in colocated mode where you can use both git and jj commands in the same repository, if that's something you or a tool you're using needs.

                  But in general jj will work with remote git repositories regardless of whether your local checkout is colocated or not, and there's no problem using it side-by-side on the same repo with other people who use git.

                  I posted an article (not mine) about it here a while ago. https://discuss.tchncs.de/post/26573114

                  Q 1 Reply Last reply
                  0
                  • Q [email protected]

                    Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
                    I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
                    So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

                    ? Offline
                    ? Offline
                    Guest
                    wrote on last edited by
                    #9

                    @QuazarOmega I always do `git branch tmp` before doing a rebase, to have a backup. Also useful for checking nothing got lost in conflict resolution. #git

                    Q 1 Reply Last reply
                    0
                    • ? Guest

                      @QuazarOmega I always do `git branch tmp` before doing a rebase, to have a backup. Also useful for checking nothing got lost in conflict resolution. #git

                      Q This user is from outside of this forum
                      Q This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #10

                      That's not what I need, I can just abort the rebase in this case and I'd get back my branch as it was before I started, but I explicitly want to go to a state in the middle so not as to lose the modifications that I did intend to do.
                      Aside from that, I also do that, have seen what hell can be like in rebasing, so knowing where you started is always valuable, I agree

                      A 1 Reply Last reply
                      0
                      • 2xsaiko@discuss.tchncs.de2 [email protected]

                        Right, you need to first restart the rebase, then git reset --hard to whatever commit from the reflog, then edit the todo list. Might need git rebase --skip too to make it read the next entry. I haven't done this myself yet fwiw.

                        It says it can use Git as backend, so that means I could do these kinds of operations easily without stringing several commands together on the repositories I’m already working on without changing them?

                        You can either clone a repo fresh or have it take over an existing git repo that you already have cloned locally. Normally you can only use its own commands, but you can create a repo in colocated mode where you can use both git and jj commands in the same repository, if that's something you or a tool you're using needs.

                        But in general jj will work with remote git repositories regardless of whether your local checkout is colocated or not, and there's no problem using it side-by-side on the same repo with other people who use git.

                        I posted an article (not mine) about it here a while ago. https://discuss.tchncs.de/post/26573114

                        Q This user is from outside of this forum
                        Q This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #11

                        Really cool, I'll give jj a try sometime, thanks for bringing it to my attention!
                        As for the rebase I'll try in a toy repo, if it works as expected it would be great, this time I ended up aborting and starting over, this time doing several rebases on the same range of commits to eventually get to the result I wanted without having to fear losing/breaking something or caving due to the cognitive load of managing many commits at a time

                        2xsaiko@discuss.tchncs.de2 1 Reply Last reply
                        0
                        • Q [email protected]

                          Really cool, I'll give jj a try sometime, thanks for bringing it to my attention!
                          As for the rebase I'll try in a toy repo, if it works as expected it would be great, this time I ended up aborting and starting over, this time doing several rebases on the same range of commits to eventually get to the result I wanted without having to fear losing/breaking something or caving due to the cognitive load of managing many commits at a time

                          2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
                          2xsaiko@discuss.tchncs.de2 This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #12

                          Another thing about jj which I really love: it makes it a lot more easy to maintain a bunch of PR branches at once. Look at this 8-way-merge here on my fork (2xsaiko): https://github.com/mesonbuild/meson/network. The tip of that is what I'm developing on top of and then squashing changes into one of the commits in one of the branches which are mostly PRs. And rebasing the entire thing on top of upstream's master is essentially trivial, best case it's one command. See https://ofcr.se/jujutsu-merge-workflow for details on how it's done!

                          Q 1 Reply Last reply
                          0
                          • Q [email protected]

                            Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
                            I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
                            So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

                            F This user is from outside of this forum
                            F This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #13

                            If I'm understanding you correctly, you can create a branch to mark where you are git branch tmp then abort the rebase. Switch to tmp get the history like you wanted, then switch back. Finally do a git rebase -i again, but immediately git reset --hard tmp. Now you have the resolved commits you want, and can delete any you don't want to do again with git --edit-todo.

                            Maybe.

                            Q 1 Reply Last reply
                            0
                            • Q [email protected]

                              That's not what I need, I can just abort the rebase in this case and I'd get back my branch as it was before I started, but I explicitly want to go to a state in the middle so not as to lose the modifications that I did intend to do.
                              Aside from that, I also do that, have seen what hell can be like in rebasing, so knowing where you started is always valuable, I agree

                              A This user is from outside of this forum
                              A This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #14

                              That's not what I need

                              That's maybe something I think is sus. If it's at all possible, make a before-rebase branch, and make a small change in a rebase, check that the results are the same, then do another. I wrote git-test specifically for this work flow. (it runs tests, but only if the tree is one or hasn't seen before)

                              https://github.com/spotify/git-test

                              Q 1 Reply Last reply
                              0
                              • Q [email protected]

                                Hi, I've got myself stuck on an issue, I've started a big rebase (I know that was already a bad idea to begin with, but, just in case, the information I'm looking for could always come in handy in other occasions), I reordered a few commits and squashed some, while in the process I resolved a few conflicts, then after I resolved one of them and got to the next conflict I realised that I shouldn't have put a certain commit there, is there a way to rewind the process to the previous step while staying in the rebase? That way I could move the commit to where it should be and continue.
                                I know you can edit the todo (git --edit-todo), but that only works for the next commits, I also can't just reset back by the number of commits I want, e.g. git reset --hard HEAD~4, because for the rebase those commits remain as done and doing git rebase --continue only brings me to where I am already, the next conflict to resolve.
                                So I wonder, is there a way to move out commits of the done list back into todo? Also for example if I trashed an unmerged file completely while messing around, so I can get it back to its initial state, this would be extremely useful

                                footfaults@lemmygrad.mlF This user is from outside of this forum
                                footfaults@lemmygrad.mlF This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #15

                                If you are continually rebasing and having to fix the same merge conflict over and over, you should look at https://git-scm.com/book/en/v2/Git-Tools-Rerere

                                Q 1 Reply Last reply
                                0
                                • A [email protected]

                                  That's not what I need

                                  That's maybe something I think is sus. If it's at all possible, make a before-rebase branch, and make a small change in a rebase, check that the results are the same, then do another. I wrote git-test specifically for this work flow. (it runs tests, but only if the tree is one or hasn't seen before)

                                  https://github.com/spotify/git-test

                                  Q This user is from outside of this forum
                                  Q This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #16

                                  My issue wasn't so much if it managed to run and more of "I don't want this change to have happened here" kind of thing, still that's a neat tool! I wish I could use it, but the codebase I'm working on is in such a hugely sorry state, no testing suite set up is the last of the many problems that most likely won't be solved because they're not "important enough", not like features (built with cardboard and duct tape), yeah we can't allocate much time at all to code quality and general work for the project infrastructure if we can call it that.
                                  About the generic advice of making smaller rebases one by one, yes, I'll learn to do that, I also solved it like that in the end

                                  1 Reply Last reply
                                  0
                                  • footfaults@lemmygrad.mlF [email protected]

                                    If you are continually rebasing and having to fix the same merge conflict over and over, you should look at https://git-scm.com/book/en/v2/Git-Tools-Rerere

                                    Q This user is from outside of this forum
                                    Q This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #17

                                    Not exactly, because n commits will have been squashed into one, so making the edit would lose the reference to the originals which should have been squashed with other commits, visually maybe this helps:

                                    A (pick) -> B (squash) -> C (squash) -> D (pick)
                                    

                                    When it should have been:

                                    A (pick) -> B (squash) -> D (pick) -> C (squash)
                                    

                                    I had just created A+B+C, then realised C should have been out

                                    footfaults@lemmygrad.mlF 1 Reply Last reply
                                    0
                                    • M [email protected]

                                      Whatever you do, familiarize yourself with git reflog. It contains all the commits, regardless of your current branch state. Even ones you might think you lost. (For about two weeks until it cleans itself up.)

                                      In your shoes, I usually abort the rebase and start a new branch and cherry-pick the commits I need.

                                      It takes awhile, but it's reliable.

                                      Source: In my overconfidence, I screw up my local git state pretty often.

                                      Q This user is from outside of this forum
                                      Q This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #18

                                      How does cherry picking improve the workflow? I'm not sure I understand, is it so you can keep the original branch as reference and know where you could have screwed up if it happens?

                                      M 1 Reply Last reply
                                      0
                                      • 2xsaiko@discuss.tchncs.de2 [email protected]

                                        Another thing about jj which I really love: it makes it a lot more easy to maintain a bunch of PR branches at once. Look at this 8-way-merge here on my fork (2xsaiko): https://github.com/mesonbuild/meson/network. The tip of that is what I'm developing on top of and then squashing changes into one of the commits in one of the branches which are mostly PRs. And rebasing the entire thing on top of upstream's master is essentially trivial, best case it's one command. See https://ofcr.se/jujutsu-merge-workflow for details on how it's done!

                                        Q This user is from outside of this forum
                                        Q This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #19

                                        That looks pretty crazy! I kinda want to unlock this power ngl

                                        1 Reply Last reply
                                        0
                                        • F [email protected]

                                          If I'm understanding you correctly, you can create a branch to mark where you are git branch tmp then abort the rebase. Switch to tmp get the history like you wanted, then switch back. Finally do a git rebase -i again, but immediately git reset --hard tmp. Now you have the resolved commits you want, and can delete any you don't want to do again with git --edit-todo.

                                          Maybe.

                                          Q This user is from outside of this forum
                                          Q This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #20

                                          Hmm, that sounds like it could be what I'm looking for, had never consider you could branch while in the middle of a rebase, nice!

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups