On Thu, Oct 12, 2017 at 12:59:06PM -0500, Mahmoud Al-Qudsi wrote: > Hello list, > > Running git 2.7.4, I’ve run into an issue where control codes that would > normally be escaped when using `git diff` are not similarly escaped when using > `git add -p`. > > As a concrete example, I have a text file including the following "text": > > :map ^[[H <Home> > :map ^[[5~ ^B "page up > :map ^[[6~ ^F "page down The diffs generated for "git diff" and "git add -p" are done by the exact same code. And that code doesn't do any escaping or cleverness; it will output the raw bytes of the difference. What is likely causing the different in what you see is that "git diff". outputs through a pager, and the snippets of "add -p" do not. The default pager, "less", does escape some control codes (but with the -R option, which git uses by default, it passes through colors). Try: git --no-pager diff or: GIT_PAGER=cat git diff and you'll likely see output similar to what you get with "add -p". The reason that "add -p" doesn't go through a pager by default is simply that it would be annoying, since we show snippets and then ask for user input. However, since Git v2.9.0, "add -p" (and all of the interactive commands like "checkout -p", etc) know about the interactive.diffFilter config option. You could use that to munge the results however you like. E.g.: # we can't use [:cntrl:] here because we want to keep newlines. # likewise, we want to keep ESC for color codes git config interactive.diffFilter "tr '\000-\011\013-\032\034-\037' '?'" -Peff