Continuando con https://stackoverflow.com/a/20574486/4935114 , @Mike propuso crear un pre-commitgancho que se incluirá grepen los archivos organizados para las líneas que uno podría querer ignorar. El gancho comprueba si esas líneas se organizaron. Si es así, echoes una advertencia y exitestá con código, 1por lo que el proceso de confirmación no continuará.
Inspirado por la respuesta de @ Mike , me encontré usando quizás una versión mejorada de su gancho que automáticamente reset envía (con la -pbandera) la línea específica que queremos ignorar.
No estoy seguro de que este gancho funcione para una situación en la que tiene muchos archivos con esta línea para ignorar, pero este pre-commitgancho busca un cambio en esta línea en un archivo específico buildVars.java. El script de gancho se veía así cuando lo probé en mi máquina.
#!/bin/sh
# this hook looks for lines with the text `var isPhoneGap = false;` in the file `buildVars.java` and it resets these lines to the previous state before staged with `reset -p`
if [[ $(git diff --no-ext-diff --cached buildVars.java | grep --count -e "var\ isPhoneGap[\ ]*=[\ ]*") -ne 0 ]]; then
cat <<EOW
WARNING: You are attempting to commit changes which are not supposed to be commited according to this \`pre-commit\` hook
This \`pre-commit\` hook will reset all the files containing this line to it's previous state in the last commit.
EOW
echo /$'\n'isPhoneGap$'\n'y$'\n'q | git reset -p
# BONUS: Check if after reseting, there is no actual changes to be commited and if so, exit 1 so the commit process will abort.
if [[ $(git diff --no-ext-diff --cached | wc -l) -eq 0 ]]; then
echo there are no actual changes to be commited and besides the change to the variable \'isPhoneGap\' so I won\'t commit.
exit 1
fi
fi
Explicación
Lo que hice fue repetir una secuencia de control que busca la expresión regular isPhoneGapdurante un resetproceso interactivo . Así emulando a un usuario que presiona /para buscar isPhoneGap, presiona ycuando se le pregunta si quiere descartar este parche y finalmente presiona qpara salir del interactivo reset.
El proceso de parche inverso interactivo se documenta aquí: https://git-scm.com/docs/git-add#git-add-patch
NOTA: El script anterior asumiendo que la variable interactive.singleKeyes false. Si configuró el suyo para true, elimine cualquiera $'\n'del echocomando justo después de la advertencia.