Git command output shows special characters

本秂侑毒 提交于 2021-02-17 03:56:11

问题


For the past few days, we are seeing a strange behavior on executing Git commands.

Command executed: git show 08fcf54adc7bbb75a54b14625fdeea7608d44a23 > sample.patch

On opening the file sample.patch through vi editor, we are seeing a lot of special characters; a sample output file looks like:

^[[33mcommit 08fcf54adc7bbb75a54b14625fdeea7608d44a23^[[m

 Author: Anshul Gupta <anshul.gupta@lnttechservices.com>

 Date:   Wed Nov 26 23:27:20 2014 +0400

     Remove redundant logs from EPD driver

     Change-Id: I078584ddd7a58da1052a8d46fd59af722e11136b

 ^[[1mdiff --git a/drivers/video/s1d13522/s1d13522fb.c b/drivers/video/s1d13522/s1d13522fb.c^[[m

 ^[[1mindex ca568ad..5e67de6 100644^[[m

 ^[[1m--- a/drivers/video/s1d13522/s1d13522fb.c^[[m

 ^[[1m+++ b/drivers/video/s1d13522/s1d13522fb.c^[[m

 ^[[36m@@ -1099,7 +1099,7 @@^[[m ^[[mstatic void s1d13522fb_display_init_wq(struct work_struct *work)^[[m

Note1: The issue is seen only for one particular user(on Ubuntu server). So possibly it looks like the configuration issue with Git or maybe vi editor.

Note2: The normal file redirection seems to be working fine. Example cat abc > xyz, the contents are copied properly with no special characters

Any help would be highly appreciated.


回答1:


Check the Git color settings. It looks like they're set to true for this particular user, but you want to use auto instead.

The characters you're seeing are color codes for the terminal. With a color setting of auto, they shouldn't be visible when piping to vi.

Check out a more detailed question/answer here: https://unix.stackexchange.com/questions/44266/how-to-colorize-output-of-git

Git Documentation: http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Colors-in-Git

The default value is auto, so it looks like the user in question has a local configuration overriding the default values.



来源:https://stackoverflow.com/questions/27396392/git-command-output-shows-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!