Git: how to automate interactive reboot / replace it with equivalent git commands

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

In the svn → git transition, I need to reinstall the newly created git repository in order to fix the “trimming history” made during SVN. Here is my manual workflow to fix the problem.

branchNEW: containing history from SOMEDAY until now branchOLD: containing history from past to SOMEDAY 

EDIT or as ascii:

 branchNEW: Y - Z branchOLD: W - X 

Both branches do not have common commits.

The basic idea is to simply reinstall branchNEW to branchOLD. Unfortunately, there was SOMEDAY refactoring: some files were moved to another directory. The result of the update is that every moved file exists in both places.

EDIT

 some file exist in X the (nearly) same files also exist in Y, just on another path branchNEW: W - X - Y - Z (after rebase) 

After rebooting, HEAD now contains the X and Y files. I also tried adding a new commit to branchOLD, which removes the old files. After rebooting, SVN-HEAD and git-HEAD are binary identical, but "git log -follow" does not work.

Now to the main problem: I can fix this using a second interactive rebase:

 git rebase -i SHA 

SHA is the sha-id of the old root commit in branchNEW. Now in the editor I need to change “pick” to “edit” for the topmost commit. After exiting the editor, I now need to delete the wrong files

 git rm -f fileA fileB git commit --amend git rebase --continue 

After that, the HEAD from git is binary, identical to the SVN chapter and, in addition, git has a complete history, and also “git log --follow” works for moved files.

Since this step is only a small part of the huge VCS transition in the future, I need a script to complete the process. But how to automate the above steps?

(I know that the SHA will not remain the same, but I can get the required SHA from svn-id, which is embedded in every commit message)

+6
source share
2 answers

I found a possible solution:

git rebase --interactive sends the "redirect list" (a list to which you can select, save, change, ...) to the editor. What type of editor can be customized. So the solution is to set up an alternative “editor” only for this interactive rebase. This can be done using the GIT_SEQUENCE_EDITOR environment variable:

 GIT_SEQUENCE_EDITOR="command" git rebase -i SHA 

the command can be a shell script or just plain sed:

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

Important: The “rebuild list” is passed as a file to the command. Therefore, the command must accept the file name as a parameter and must write the result to the same file. "sed -i" does just that.

+3
source

expect can also help you. Although this is not exactly what you need to do, you should use something similar to automate the process:

 #!/usr/bin/env expect spawn git rebase -i HEAD~2 # down, delete word, insert 's' (for squash), Escape, save and quit send "jdwis \033:wq\r" expect "# This is a" # down 4, delete 3 lines, save and quit send "4j3d:wq\r" interact 
0
source

Source: https://habr.com/ru/post/975548/


All Articles