Mac: git diff - better colors? - macos

Is there a way to get better colors for git diff on a Mac? Something more like Linux' colors. In the diff, the lines that are removed are highlighted and colored, but added lines are grey. Grey?! :) (Granted, it's slightly bolded, but it's still hard to parse through the information when it's grey...)
Thanks!

The style of the parts of Git's diff are set with the color.diff.<slot> config parameters, where <slot> is the part of the diff, in this case new. git help config provides further information, but in short, set something like this in your Git config file:
[color "diff"]
new = green
Or to set it with a command:
git config --global color.diff.new green
If, for some reason, you only want to set it in a certain repo, just run it without --global.
I recommend spending some time reading the configuration documentation: There are many things one can set in one's Git configuration to make Git more like one wants it.

Related

Write Git commit message in different editor than default

I'd like to be able to occasionally use a different editor when writing commit messages. I've found plenty of answers on how to change the default editor, but I don't want to change that - VIM is normally fine. What I'd like is some option like git commit --editor=<editor_name> where <editor_name> is the editor I want to use when writing the commit message for that commit only.
The only thing I've found that is similar to what I'd like is opening a new file with <editor_name> <newcommitfilename>, write message, save and close file, then use git commit -F <newcommitfilename>.
Is there an easier way to achieve this?
Thanks!
All Git commands use the form:
git <verb>
You may insert options before the verb, e.g.,
git -c core.pager=cat show
The -c option in particular takes a configuration item name, such as core.pager, core.editor, user.name, and so on, and a value, joined with an equals sign = like this.
Since your goal is to use a particular editor, git -c core.editor=whatever commit does the trick.
As several commenters noted, there are other ways to do this. For the editor in particular, the environment variable $GIT_EDITOR overrides core.editor, so:
GIT_EDITOR=nano git commit
runs git commit with GIT_EDTIOR set to nano for the duration of the one command (assuming POSIX-style shell).

Why does my git shell look like this on my laptop: [name#name-Laptop ~ (master *+)]$, but not on desktop

On my desktop, git looks like this:
On my laptop, git looks like this: [name#name-Laptop ~ (master *+)]$.
Here is an image to get a better idea of what git looks like on my laptop:
I have uninstalled and reinstalled git on my laptop, but after doing a normal setup as stated by multiple videos git always ends up as shown in the Incorrect Git.jpg file. How do I get git on my laptop to look like git on my desktop (Correct Git.jpg). I am using the VIM editor for both.
Any help would be much appreciated.
export PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u#\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]__git_ps1\[\033[0m\]\n$' is the solution.
So I found out that the PS1 was to configure the editor as William Pursell mentioned in the comments above. My configuration before was set up as [\u#\h \W$(_git_ps1 " (%s)")]\$. This gave me that white text for everything in git bash as shown above. By changing the PS1 to the configuration in my answer, I was able to get the colorful setup, shown above, for git bash on my laptop. I was able to get that long configuration by using echo "$PS1" and copied that over to my laptop. It looks much cleaner to me and is able to make navigation much easier. Also, thank you for the welcome!

Git colors don't display in Windows command prompt

I assume that it's because of the color setting in my config file, but I've tried changing that to no avail. Maybe I'm not doing that right?
Notice that Git Bash shows branch color in green, but on window cl it's not showing at all!
$ git branch
* add_bower *<~~~ only the asterisk appears on the windows prompt.*
master
git in cmd should work just fine. I would check both your gitconfig local and gitconfig global before giving up here.
the first thing I would do is a
git branch --color
or
git diff --color
you can also use the -c option
git -c color.ui=always status
if you see colors then what is likely happening is your local gitconfig is overriding the setting in your global gitconfig
at that point do a
git config --local --edit
if things say auto or true and you still don't see colors. set the output to always. I recommend this b\c it is possible for git to make mistakes and not treat cmd as a terminal
from git-config:
If this is set to always, git-diff(1), git-log(1), and git-show(1)
will use color for all patches. If it is set to true or auto, those
commands will only use color when output is to the terminal. Defaults
to false.
like so
[color]
branch = always
diff = always
interactive = always
status = always
ui = always
hope this helps!
I don't think the command prompt will support coloring different parts of the output out of the box. You'd probably need some extension or add-on to handle it. Have you considered using Powershell? In addition to the built-in support for the coloring you're looking for, it's also much more versatile and powerful than the normal command prompt.
I'm seeing the exact same problem, only for some command prompts. (By default it works, but when I run my team's "razzle" customization script the output is broken like your screenshot. Oddly, coloring in git log and status works fine; just branch is broken.)
I created a new shortcut that launched the same customization script, and the output is fixed for my new shortcut. Very weird.
If you run git branch --no-color you see the right output, just without color?
You can run git config --local --add color.branch never to set that as the default for this repo.

How to get colored output with git+mintty+mingw on windows?

I have installed the official windows git distribution, and I installed a recent mingw, and into that the mintty terminal. Then I have copied my git installation to this mingw installation, and now it works from within mintty. My only problem is that the git output is not colored. I suspect that this is because the windows git port tries to use the windows console color thingie and not the ANSI color codes which mintty would be able to interpret. Is it possible to make git use the ANSI color codes instead?
(I have tried a cygwin setup prior to this, but the performance was very, very bad, and I could not find any solution to that).
from git-config:
If this is set to always, git-diff(1), git-log(1), and git-show(1) will use color for all patches. If it is set to true or auto, those commands will only use color when output is to the terminal. Defaults to false.
It looks like git isn't treat mintty as terminal. For me using always instead of true/auto helps:
[color]
status = always
Forcing color by adding --color flag to diff command work as well (with diff=true):
git diff --color
It's simple. Config git to always show color in any ui.
git config --global color.ui always
Works for me.

Git Windows Command Prompt gets stuck during Git commands with (END)

I've got Git for Windows setup (msysgit) and it was working fine for the last few days and today I've encountered an odd error.
When issuing a Git command in the Windows Command Prompt or in the Git Bash that comes bundled with msysgit, I get a strange '(END)' line appear and then I cannot issue any other comamnds.
At this point all I get are system beeps.
Any ideas?
Thanks, P.
Git want to show more than one screen of information to you, to do so it call the standard unix pager program less. Just type q to return to the prompt when you no longer want to navigate in the output.
j move one line down
k move one line up
<space> move one page down
b move one page up
h show the help
If you want to use git efficiently you should learn the basic unix tools. Even if git build and run on windows it's pretty much an alien software on the platform.
If you don't want less just replace it with another pager in the configuration. If you don't want a pager at all just use cat :
git config --global --add core.pager cat
Press q to exit the pager (which is less in git by default).
I first came across this question when I was looking for the same thing; to not have to exit out of the log command. I have since found the answer I like, so even though it is well after the original asking I will add this answer to provide an additional solution that I didn't find quickly in my own search.
Others have stated why the (END) is present -- the results are being piped thru a pager, one that can be configured for a different pager.
However, I sometimes don't want it to stop at all; because I've specified other options that do the limiting. I found that for this git has a global option --no-pager to turn off the whatever pager is defined in the config file.
This global option is on the git command itself, is available for all subcommands and is placed before the subcommand like this:
git --no-pager log
Git is using the "pager" called less, which allows you to scroll through large amount of program output easily. However, the default settings on Git for Windows seem to be to keep the pager running even when there is less than one screen of output.
Here is the default setting I had before, which would always show the (END) and wait for you to hit q before returning you to your prompt:
$ git config --get core.pager
less -+F
You can change the behavior so that less will only keep running (and take control of the keyboard) when there is more than a screenful of output by changing the option to -F instead of -+F.
Fix the pesky pager with
$ git config --global core.pager "less -F"
(The -+X option syntax for less is documented to reset the -X option to its "default", although that is not the behavior I observed with -+F since removing the option altogether was equivalent to -F, not -+F.)

Resources