git/list[1] front-page[2] threads[3] people[4] search[5] about
 

BUG: git subtree split - revert commit followed by a merge

From
MBMachiels, Brecht <brecht.machiels@kla-tencor.com>
Date
Aug 27, 2013, 13:09 UTC
Message-ID
<E71F820BDC168F4B91A464A8FD8ABBD8389BD9C7@CH1PRD0310MB391.namprd03.prod.outlook.com>
Hello:
I'm running into the problem described in this mailing list post:
	http://thread.gmane.org/gmane.comp.version-control.git/202645
 'git subtree split' fails to reconstruct the history when a revert commit is followed by a merge commit. I have slightly adjusted the test script provided by Fabien in his mailing list post:
    git init
    
    # create a directory that is going to be split
    mkdir doc
    echo "TEST" > doc/README
    git add doc
    # commit A
    git commit -a -m"first version"
    
    # create a branch with a new commit (Z)
    git checkout -b test
    echo "TEST" > doc/README1
    git add doc/README1
    git commit -a -m"added README1"
    git checkout master
    
    # modify the README file (commit B)
    echo "TEST_" > doc/README
    git commit -a -m"second version"
    
    # revert the change (commit C)
    echo "TEST" > doc/README
    git commit -a -m"revert second version"
    # or use git revert HEAD^
    
    # split
    git subtree split --prefix="doc" --branch=TARGET
    
    # add another commit (to a file *not* in the subtree dir)
    echo "BLA" > BLA
    git add BLA
    git commit -a -m"third version"
    
    # adding another commit to a file in the subtree dir will "fix" things
    #echo "MEH" > doc/MEH
    #git add doc
    #git commit -a -m"fourth version"
    # the log will show the 3 commits as expected (including B and C)
    GIT_PAGER= git log --oneline TARGET
    
    # merge the test branch
    git merge -m"merged test" test
    
    # attempt to re-split; this will fail
    git subtree split --prefix="doc" --branch=TARGET
    
    # see what history split generates
    git subtree split --prefix="doc" --branch=TARGET2
I have discovered that if the revert commit is followed by another commit that makes changes in the subtree directory, the split will work as expected (see "fourth version" above).
See also this related SO question where I ask for a workaround: http://stackoverflow.com/questions/18465867

Best regards, Brecht

Next: Brecht Machiels
Message 1 of 2 in “BUG: git subtree split - revert commit followed by a merge”
  1. Machiels, BrechtAug 27, 2013
  2. Brecht MachielsAug 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.