[Vm-dev] Should I push or request a pull?

Ben Coman btc at openinworld.com
Tue Jun 28 17:45:19 UTC 2016


On Wed, Jun 29, 2016 at 1:38 AM, Ben Coman <btc at openinworld.com> wrote:
> On Tue, Jun 28, 2016 at 11:41 PM, Ben Coman <btc at openinworld.com> wrote:
>> On Sun, Jun 26, 2016 at 4:51 AM, Tim Felgentreff
>> <timfelgentreff at gmail.com> wrote:
>>>
>>>
>>> Hi Ben,
>>>
>>> One of your arguments is about history cleaning.
>>> Mostly my discouraging of rebase -i comes from experience with people who made a mistake (e.g. as simple as deleting a line and then getting "lucky" and having git not complain about conflicts during the rebase) to lose a commit entirely. And sometimes they continued working for a while, eventually a git gc was triggered, and then that commit was cleaned up and was lost for good by the time they noticed their work was gone. This happened to people around me more than just once, and then I wasn't able to help because git gc had run. Eventually I gave up and encouraged people who do not want to spend the time to really put in the work and understand how git works and what the internal structures are to not use rebase.
>>
>> Ah, it never cross my mind to delete a line. So I never hit the problem.

So of course I had to experiment to understand properly.
The log is a bit long, but maybe a handy reference...
Each experiment delineated by "#===="

TL;DR - check out the last two examples.


#====SETUP MASTER

$ mkdir testrebase && cd testrebase
$ git init
$ echo M >> blah ; git add blah ; git commit -m M


#====NORMAL SQUASH ONLY, NO DELETES

$ git checkout -b testSquashOnly master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
    M
    1
    2
    3
    4

    b9784f0 4
    97df945 3
    c57a0e6 2
    77366e2 1
    9b9b515 M

$ git rebase -i master
# in editor, change commit 2 to squash, save, exit
# in second editor, change commit message to "1&2", save, exit

$ cat blah ;  git log --oneline
    M
    1
    2
    3
    4

    15cbb61 4
    6416fd2 3
    3b00e2a 1&2
    4bba92f M

No changes lost.  History cleaned okay.


#====DELETE,ERROR,ABORT

$ git checkout -b testDeleteAbort master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git rebase -i master
# in editor, delete commit 2 line, save, exit
    error: could not apply 97df945... 3
    When you have resolved this problem, run "git rebase --continue".
    If you prefer to skip this patch, run "git rebase --skip" instead.
    To check out the original branch and stop rebasing, run "git
rebase --abort".
    Could not apply 97df94529f50a597489a53bf21f25a9c270226a0... 3

# error??!! ==> panic!!! ==> abort
$ cd rebase --abort
$ cat blah ;  git log --oneline
    master
    1
    2
    3
    4

    b9784f0 4
    97df945 3
    c57a0e6 2
    77366e2 1
    9b9b515 master

Abort on all errors is okay.


#====DELETE,ERROR,EDIT,CONTINUE

$ git checkout -b testDeleteMerge master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git rebase -i master
    # in editor, delete commit 2 line, save, exit
    error: could not apply 97df945... 3

# open editor on file blah
# remove line <<<< ==== >>>> inserted by rebase, to end up with...
      master
      1
      2
      3

$ git add blah;  git rebase --continue
    [detached HEAD 1f5ed82] 3
     1 file changed, 2 insertions(+)
     Successfully rebased and updated refs/heads/test.

$ cat blah ;  git log --oneline
    master
    1
    2
    3
    4

    ef57ae0 4
    1f5ed82 3
    77366e2 1
    9b9b515 master

All changes survived, but there is a risk of losing changes
if wrong lines merged in editor.


#====DELETE,ERROR,CONTINUE(WITHOUT EDIT)

$ git checkout -b testDeleteMerge2 master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git rebase -i master
    # in editor, delete commit 2 line, save, exit
    error: could not apply 97df945... 3

# note, no edit of blah
$ git add blah;  git rebase --continue
    # in editor, save, exit
    [detached HEAD bf742d8] 3
     1 file changed, 5 insertions(+)
    error: could not apply 83209d3... 4

$ git add blah;  git rebase --continue
    # in editor, save, exit
    [detached HEAD 42ab0c6] 4
     1 file changed, 4 insertions(+)
    Successfully rebased and updated refs/heads/testDeleteMerge2.

$ cat blah ;  git log --oneline
    M
    1
    <<<<<<< HEAD
    =======
    2
    3
    <<<<<<< HEAD
    >>>>>>> 7176be1... 3
    =======
    4
    >>>>>>> 83209d3... 4
    42ab0c6 4
    bf742d8 3
    a13429f 1
    4bba92f M

Urgh! No lines actually lost, but an awful mess to clean up.


#====DELETE,ERROR,SKIP

$ git checkout -b testDeleteSkip master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git rebase -i master
    # in editor, delete commit 2 line, save, exit
    error: could not apply 97df945... 3

$ git rebase --skip
    error: could not apply b873786... 4

$ git rebase --skip
    Successfully rebased and updated refs/heads/testDeleteSkip.

$ cat blah ;  git log --oneline
    M
    1
    fc67d5e 1
    4bba92f M

OUCH!! CHANGES LOST!!!!  AAARRRGGHHH!!


#====THE FOLLOWING REQUIRES git --version  > 2.6.0


#====DELETE, missingCommitsCheck WARN

$ git checkout -b testMissingCommitsCheckWarn master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git config rebase.missingCommitsCheck warn
$ git rebase -i master
    # in editor, delete commit 2 line, save, exit
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
 - 304610b 2
To avoid this message, use "drop" to explicitly remove a commit.

Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
The possible behaviours are: ignore, warn, error.

error: could not apply a427113... 3

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply a427113b3137a1e585fcd04dcdd64c899fa4f163... 3

SO WITH WARN WE ARE STILL PRESENTED WITH THE CHOICE TO SKIP, ETC...


#====DELETE, missingCommitsCheck ERROR

$ git checkout -b testMissingCommitsCheckError master
$ for N in 1 2 3 4 ;  do (echo $N >> blah ;  git commit -am $N) ;  done
$ cat blah ;  git log --oneline
     # as above

$ git config rebase.missingCommitsCheck error
$ git rebase -i master
    # in editor, delete commit 2 line, save, exit
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
 - 08d9c7b 2
To avoid this message, use "drop" to explicitly remove a commit.

Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
The possible behaviours are: ignore, warn, error.

You can fix this with 'git rebase --edit-todo'.
Or you can abort the rebase with 'git rebase --abort'.

SO WITH ERROR WE ARE PRESENTED WITH SAFER OPTIONS

cheers -ben.


More information about the Vm-dev mailing list