Can git automatically split a commit into separate chunks?
As explained in the previous questions , you can split commits into smaller patches. However, these answers recommend git add -p
which does the job, but tediously if all I want is to have one commit for each file in a given order in the file. Is there a way to achieve this, automatically?
+3
source to share
1 answer
You can do something like
echo -e "y\nq" | git add -p && git commit -m "automated"
which does:
echo y (accept first hunk), then q (quit) for next hunk, commit with given message.
Loop until git commit
it returns success:
s=0
i=1
while [ $s -eq 0 ]
do
echo -e "y\nq" | git add -p && git commit -m "automated $i"
s=$?
let i=$i+1
done
or in one line:
s=0; i=0; while [ $s -eq 0 ]; do echo -e "y\nq" | git add -p && git commit -m "automated $i"; s=$?; let i=$i+1; done
Produces commits such as
c5ba3 - (HEAD) automated 3
14da0 - automated 2
6497b - automated 1
+5
source to share