简体   繁体   English

奇怪的输出git diff到Ubuntu中的文件

[英]Strange output of git diff to file in Ubuntu

Ubuntu 13.04. Ubuntu 13.04。 I want to create a patch and there is no problem when I'm using Netbeans or other IDE but when I run in command line: 我想创建一个补丁,当我使用Netbeans或其他IDE但我在命令行中运行时没有问题:

git diff > 1.patch

and then 接着

cat 1.patch

output looks like this: 输出看起来像这样:

diff --git a/sites/all/modules/pet/pet.module b/sites/all/modules/pet/pet.module
index adfd273..1091090 100755
--- a/sites/all/modules/pet/pet.module
+++ b/sites/all/modules/pet/pet.module
@@ -71,7 +71,7 @@ function pet_access($op, $type = NULL, $account = NULL) {
 /**
  * Implements hook_permission().
  */
-function pet_permission() {  
+function pet_permission() {
   $permissions = array(
     'administer previewable email templates' =>  array(
       'title' => t('Administer previewable email templates'),
@@ -183,26 +183,26 @@ function pet_lookup_uid($mail) {
 /**
  * Send tokenized email to a list of recipients.
  *
- * Given a list of recipients, and an optional node id, perform token 
+ * Given a list of recipients, and an optional node id, perform token
  * substitution and send an email to each. The node substitutions, if any,
  * are the same in each email sent.  The user tokens, if any are custom based
- * on the account (if any) associated with each email.  
+ * on the account (if any) associated with each email.
  *
  * @param $name
  *   The unique name of the PET template.
  * @param $recipients
  *   An array of at least one recipient in one of two formats:
  *      1. a simple email address, in which case the uid is looked up
- *      2. an array('mail' => <email address>, 'uid' => <uid>) in which case 
+ *      2. an array('mail' => <email address>, 'uid' => <uid>) in which case
  *         the uid is already available (more efficient)
  * @param $options
  *   An array of options as follows:
  *      nid - An optional node id for token substitutions.
- *      subject - An optional subject which if provided will override the 
+ *      subject - An optional subject which if provided will override the
  *        subject in the PET.
  *      body - An optional body which if provided which will override the body
  *        in the PET.
- *      body_plain - An optional plain text body which if provided which will 
+ *      body_plain - An optional plain text body which if provided which will
  *        override the plain text body in the PET.
  *      from - An optional from email which if provided which will override the
  *        from in the PET (which in turn overrides the site default).
@@ -221,12 +221,12 @@ function pet_send_mail($name, $recipients, $options) {
     watchdog('pet', 'At least one recipient must be provided for PET %name.', array('%name' => $name), WATCHDOG_NOTICE);
     return;
   }

but gedit shows this: 但是gedit显示了这个:

[1mdiff --git a/sites/all/modules/pet/pet.module b/sites/all/modules/pet/pet.module[m
[1mindex adfd273..1091090 100755[m
[1m--- a/sites/all/modules/pet/pet.module[m
[1m+++ b/sites/all/modules/pet/pet.module[m
[36m@@ -71,7 +71,7 @@[m [mfunction pet_access($op, $type = NULL, $account = NULL) {[m
 /**[m
  * Implements hook_permission().[m
  */[m
[31m-function pet_permission() {  [m
[32m+[m[32mfunction pet_permission() {[m
   $permissions = array([m
     'administer previewable email templates' =>  array([m
       'title' => t('Administer previewable email templates'),[m
[36m@@ -183,26 +183,26 @@[m [mfunction pet_lookup_uid($mail) {[m
 /**[m
  * Send tokenized email to a list of recipients.[m
  *[m
[31m- * Given a list of recipients, and an optional node id, perform token [m
[32m+[m[32m * Given a list of recipients, and an optional node id, perform token[m
  * substitution and send an email to each. The node substitutions, if any,[m
  * are the same in each email sent.  The user tokens, if any are custom based[m
[31m- * on the account (if any) associated with each email.  [m
[32m+[m[32m * on the account (if any) associated with each email.[m
  *[m
  * @param $name[m
  *   The unique name of the PET template.[m
  * @param $recipients[m
  *   An array of at least one recipient in one of two formats:[m
  *      1. a simple email address, in which case the uid is looked up[m
[31m- *      2. an array('mail' => <email address>, 'uid' => <uid>) in which case [m
[32m+[m[32m *      2. an array('mail' => <email address>, 'uid' => <uid>) in which case[m
  *         the uid is already available (more efficient)[m
  * @param $options[m
  *   An array of options as follows:[m
  *      nid - An optional node id for token substitutions.[m

.

It's colorized. 它是彩色的。 <kbd>Esc</kbd>[36m is an ANSI escape sequence for a foreground color change. <kbd>Esc</kbd>[36m是前景颜色变化的ANSI转义序列。

1. Disable color 1.禁用颜色

git diff --color=never

2. Or change the config 2.或者更改配置

git config color.ui auto

This results in .git/config having: 这导致.git/config具有:

[color]
    ui = auto

auto indicates that color is automatically enabled when output is to a terminal, but not if output is to a file/pipe. auto表示当输出到终端时自动启用颜色,但如果输出是文件/管道则不会。

3. Fixing existing patches 3.修复现有补丁

Look at AnsiFilter to remove ANSI escape sequences from existing patch files. 查看AnsiFilter以从现有补丁文件中删除ANSI转义序列。

I follow this link enter link description here to see color: 我按照此链接在此处输入链接描述以查看颜色:

$ export LESS="-eirMX" $ export LESS =“ - eirMX”

You may need to edit .profile or .bashrc to permanently set environmental variables. 您可能需要编辑.profile.bashrc以永久设置环境变量。 For straight forward, all you need to do is to append the above line to one of the 3 following files: 对于直接,您需要做的就是将上面的行附加到以下3个文件之一:

~/.profile
~/.bash_profile
/etc/profile 

你可以尝试一下,它对我有用:

git config --global color.diff auto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM