07 October, 2018

`stg uncommit` the first commit

I wanted to edit the first commit of a repository using `stg`. (Actually I wanted to edit all of them, which was easy except for the first).

`stg` doesn't like this:

$ stg uncommit -n 1
Uncommitting 1 patches ... done
stg uncommit: Trying to uncommit 38a035a7667c9417e10a4f53e7c88a57711ca440,
              which does not have exactly one parent
... the root commit is not formed in the way that `stg` wants.

I worked around this by:

  1. making a new empty commit in a new repo:
    mkdir ~/empty-repo
    $ cd ~/empty-repo
    $ git init
    $ git commit -a --allow-empty -m "Empty initial commit"
    [master (root-commit) 38a035a] Empty initial commit
    
  2. getting that empty commit into my real repo ...
    $ cd ~/real-repo
    $ git remote add empty-repo ~/empty-repo
    $ git fetch empty-repo
    
  3. cherry picking the original root commit on top of the empty commit ...
    $ git tag tmp1
    $ stg pop -a
    $ git reset --hard empty-repo/master
    $ git cherry-pick tmp1
    
  4. and now this cherry-picked originally original commit can be `stg uncommit`ted:
    $ stg uncommit -n 1
    

No comments:

Post a Comment