I am trying to use git diff --color=never
in a python script, but i realized that there are escape sequences in the output of git diff
, despite the usage of the --color=never
option.
This is an example of the output:
[u'\x1b[?1h\x1b=\r\x1b[1mdiff --git a/file1 b/file1\x1b[m\x1b[m\r', u'\x1b[1mnew file mode 100644\x1b[m\x1b[m\r', u'\x1b[1mindex 0000000..e69de29\x1b[m\x1b[m\r', u'\x1b[1mdiff --git a/file2 b/file2\x1b[m\x1b[m\r', u'\x1b[1mdeleted file mode 100644\x1b[m\x1b[m\r', u'\x1b[1mindex e69de29..0000000\x1b[m\x1b[m\r', u'\r\x1b[K\x1b[?1l\x1b>']
To reproduce you can use this snippet (or something similar):
from sh import git
def main():
changes = git.diff('--color=never', 'master', 'origin/master')
changes = changes.split('\n')
print(changes)
if __name__ == '__main__':
main()
I have two questions:
Is there a way to avoid that these sequences are printed (e.g. a git option)?
Why are these sequences there and what do they do, because i do not see any colors when i invoke it from the command line.