While the correct one is: sh = !bash -c. The incorrect formulation is: sh = !bash -c. if you have a handy alias to execute a bash command in the working tree's root. This is why a " must always be escaped, even if it looks like it's inside a single-quoted string (which git is completely agnostic about). gitconfig alias parsing doesn't recognise single-quotes as anything special - its only special characters are ", \, \n, and (outside of a "-quoted string). gitconfig parser and not reach the shell. If the " character is not escaped, it will be consumed by the. The - signals end of arguments and allows for the case that you have a file named -w or something that would look like a switch to git diff.Įscaped double-quotes around are required to preserve any user-supplied quoted arguments. You may want to run this command as GIT_TRACE=1 git anw to see this in action. These arguments aren't wanted here - we don't want git apply to consume them, hence the preceding comment character. gitconfig, but instead gets passed through and is treated as a comment inside the shell - it is inserted between the end of the git apply and the user-supplied arguments that git automatically places at the end of the command line. The final # must be quoted so it's not treated it as a comment inside the. ![]() ![]() Thanks to Herbert's answer for the inspiration. gitconfig: anw = !git diff -U0 -w -no-color - | git apply -cached -ignore-whitespace -unidiff-zero "#" With this option, git diff will just drop some chunks, making the resulting patch bogus since the line numbers in the destination file are going to be off.Īdd the following to your. While this trick works as-is, if you try to use it to drop blank line changes with -ignore-blank-lines then things get complicated. The -no-color isn't required but as I have colors set to always, I have to use it. You will notice that after a git addnw your/file there will still be unstaged changes, it's the whitespaces left. Or you can simply run: git diff -U0 -w -no-color -src-prefix=a/ -dst-prefix=b/ | git apply -cached -ignore-whitespace -unidiff-zero -Īdded options -U0, and -unidiff-zero respectively to workaround context matching issues, according to this comment.īasically it applies the patch which would be applied with add without whitespace changes. Solution wasn't quite what I needed, so this is the alias I made for the exact same problem: alias.addnw=!sh -c 'git diff -U0 -w -no-color -src-prefix=a/ -dst-prefix=b/ | git apply -cached -ignore-whitespace -unidiff-zero -'
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |