Remove spurious commit parent pointer

前端 未结 4 2166
暖寄归人
暖寄归人 2020-12-06 01:24

I imported a Bazaar repository into Git (using git bzr), but the resulting repository contains a spurious commit parent link:

4条回答
  •  没有蜡笔的小新
    2020-12-06 01:58

    You can do it manually using the git commit-tree internal command.

    We want to edit the commit tagged 1.02-6 to remove the spurious parent pointer (to 56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4).

    First, read the information from the existing commit object:

    user@host:/path/repo.git$ git cat-file -p 1.02-6 
    tree c658aa1ebcf2bf2a607696c7868b875be72fb01f
    parent 56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4
    parent 4e671bf1d2298729c9e5cfd8229051cfe2c40831
    author James Damour (Suvarov454)  1146319620 -0400
    committer Bazaar Package Importer  1146319620 -0400
    
    The "main/" in the Section line of debian/control should be assumed.
    

    Extract the commit message using git log --format=%B -n 1 1.02-6.

    Now create a new commit with the same content (excluding the spurious parent link, and the committer info):

    git log --format=%B -n 1 1.02-6 | \
        GIT_AUTHOR_NAME="James Damour (Suvarov454)" \
        GIT_AUTHOR_EMAIL="suvarov454@users.sourceforge.net" \
        GIT_AUTHOR_DATE="1146319620 -0400" \
        git commit-tree c658aa1ebcf2bf2a607696c7868b875be72fb01f \
            -p 4e671bf1d2298729c9e5cfd8229051cfe2c40831
    

    This created a new commit, and printed its hash (cc32e66...). Now turn it into a new branch:

    git checkout -b fixed_commit cc32e66
    

    and rebase master onto the new branch:

    git checkout master
    git rebase fixed_commit
    

    And we're done:

    Finished

    You probably want to delete the old branches and re-tag the appropriate commits.


    Actually it might be easier to use git filter-branch --parent-filter. I haven't tried that.

提交回复
热议问题