S
S
Sergey Sashkin2020-10-23 18:47:16
linux
Sergey Sashkin, 2020-10-23 18:47:16

How to change commit comments from a file?

Guys hello! There is a task to change comments to commits in a certain branch.
There is a script which takes 2 values ​​as old and new commit. Loops (while read -r line; do) accesses lines in file file.txt each time

The script itself:

#!/bin/bash

fille="$1"

#fille="fille.txt"

while read -r line; do
  source=$(echo "$line" | awk 'BEGIN { FS = "," } { print $1} ');
  target=$(echo "$line" | awk 'BEGIN { FS = "," } { print $2} ');
  git filter-branch -f --msg-filter 'sed -e "s/'"$source"'/'"$target"'/g"'
done < "$file"

Agreer is a long time in one pass to do the operation search \ replace the 1st line, taking into account the fact that the commits + 5k
Please help with the optimization of this script.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2020-10-23
@LexPex

Please help me optimize this script.

Get rid of the loop by moving the logic inside the command passed to --msg-filter. More or less like this:
#!/bin/bash

fille="$1"

cmd=

while read -r line; do
  source=$(echo "$line" | awk 'BEGIN { FS = "," } { print $1} ');
  target=$(echo "$line" | awk 'BEGIN { FS = "," } { print $2} ');
  cmd="${cmd}s,$source,$target,g;"
done < "$file"

git filter-branch -f --msg-filter "sed -e '$cmd'"

M
mayton2019, 2020-10-23
@mayton2019

But is it possible? Git only allows you to change the latest commits by collapsing them into 1 commit (amend).
Or you can completely create a new repo and transfer all the changes there one at a time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question