git: How to automate interactive rebase / replace it by equivalent git commands

前端 未结 2 1031
孤街浪徒
孤街浪徒 2020-12-17 23:50

I need to automate a interactive rebase or replace it by other commands. Just let me explain my current situation:

In an svn->git transition i need to rebase the new

相关标签:
2条回答
  • 2020-12-18 00:14

    expect might help you, too. Though this isn't quite what you need to do, you should be able to use something similar to automate your process:

    #!/usr/bin/env expect
    spawn git rebase -i HEAD~2
    
    # change the second "pick" to "squash"
    # jump to top (if not there), down, delete word, insert 's' (for squash), Escape, save and quit
    send "ggjdwis \033:wq\r"
    
    expect "# This is a"
    
    # skip past first commit message (assumed to be one line), delete rest of file
    # down 4, delete 3 lines, save and quit
    send "4j3d:wq\r"
    
    interact
    
    0 讨论(0)
  • 2020-12-18 00:20

    I found a possible solution:

    git rebase --interactive sends the "list of rebase commits" (the list where you can pick, stash, edit, ...) to an editor. Which kind of editor can be configured. So the solution is to configure an alternative "editor" just for this interactive rebase. This can be done using the environment variable GIT_SEQUENCE_EDITOR:

    GIT_SEQUENCE_EDITOR="command" git rebase -i SHA
    

    command could be a shell script or just a simple sed:

    GIT_SEQUENCE_EDITOR="sed -i 's/^pick ce5efdb /edit ce5efdb /;/^pick ce6efdb /d'" git rebase -i SHA
    

    Important: The "list of rebase commits" is passed as file to the command. So the command must accept a filename as parameter and have to write the result to same file. "sed -i" is exactly doing this.

    0 讨论(0)
提交回复
热议问题