Commit redistribution without interactive forwarding?

Is it possible to trigger an automatic commit switch (identified by a hash) without using interactive mode? What I intend is single-line to overwrite, because I need to call the code.

UPDATE:

I changed it a bit for inline use.

git filter-branch --msg-filter "ruby -e \"puts (ENV['GIT_COMMIT'] == '1ba2dd66581f6fbc03d1a6406a0ed61b6473c9ab' ? 'new msg' : STDIN.read)\"" HEAD

It would be nice, at least in pure bash (without ruby), but I had problems getting STDIN to work (using read).

+4
source share
1 answer

git-filter-branch can do what you want. In particular, you need the --msg-filter argument:

This is a filter for overwriting commit messages. The argument is evaluated in a shell with an initial commit message on standard input; its standard output is used as a new commit message.

One wrinkle is that git-filter-branch wants to run each commit in the branch, while you only want to rewrite one commit (and then effectively recompose the rest). Thus, your message filter must have some conditional logic in order to display either a new commit comment (for the one you really want to rewrite) or the original unmodified commit message (for everything else).

This is the trick:

 git filter-branch --msg-filter "ruby /path/to/filter.rb 843c2da5e07de914ea2319fa3295730ff8b3b0a1 'New message'" HEAD 

git-filter-branch modifies the current directory before it calls your script, so you need to fully qualify /path/to/filter.rb .

Here filter.rb :

 if ENV['GIT_COMMIT'] == ARGV[0] puts ARGV[1] else puts STDIN.read end 

Most likely, this could be rewritten in more detail in the script shell, perhaps without even putting the script message filter in a separate file; but I work on Windows, so I don’t have anything like that. I have Ruby, so I used this and it works.

+5
source

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


All Articles