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).
Related
I am using Ubuntu for Windows.
Vim and git work fine when calling git commit --amend, but calling git diff or git log results in improperly formatted output. Can anyone please explain when the output is not formatted correctly like when calling git commit --amend?
I'm using zsh with git aliases, which is why it says I called gc! and not git commit --amend, etc.
The stuff you're seeing—the [32m, [m, and so on—is the result of partly, but not completely, stripping out colorization codes. Git is printing ESC [ (optional digits) m so as to tell your terminal emulator / display window to change colors, backgrounds, and so on. The pager you're using is for some reason removing the ESC but leaving the rest in.
To find out which pager you're using, use:
git var GIT_PAGER
To correct its behavior ... well, that depends on which pager you're using. :-)
Whenever I execute git log command it cannot be terminated. If I do Ctrl + C it exits paging environment but if I start to type anything it starts git log command again.
as mentioned already, git log -X will limit your output to the last X commits.
Git log and other git commands invoke the less command. This is the pager. To get help with the pager, type ? or h when looking at the output. You will now see the help for the less command. Quitting less is easy, just type q.
If you don't want log to use a pager utility, you can instruct git not to use it with:
git --no-pager log
Git log has a lot of options. To get a quick overview of what has happened, I use
git log --graph --oneline --decorate --all
Decorate can be set to be enabled by default through config so you don't have to issue it.
If you think that's a lot to write on the command line, you're right! Bash has a quick remedy for that: CTRL-R. Press that and start typing 'graph'. You should get the last time that you typed that long command. This is one reason I don't bother with git aliases; it's easy to search your command history which persists from session to session.
Further, you can limit the output of git log to a particular author or particular date range, etc.
Have fun exploring and stick to the command line. It's what git was meant to be used on. You will also be introduced to a lot of excellent bash techniques that will help you a ton as you get going further with git.
You can limit the number of commits to be shown with:
git log -n 10
To limit only to the last 10 commits.
You can use also some kind of graphic interface for git, like gitk or tig or git-cola.
Check for other gui clients here.
I'm trying to use MacVim as a default editor (on my Mac, obviously). I'd like to have MacVim to edit commit messages when I hg ci. Unfortunately when I do so (either by setting EDITOR=mvim or alias vi='mvim') MacVim pops up with an empty message (i.e. none of the boilerplate in the bottom half), and when I save that commit message I get the error "abort: empty commit message".
Is there a way to use MacVim (presumably via mvim) to edit the commit messages when checking in changes with Mercurial?
Thank you for reading, and I look forward to reading the answers.
Brian
Set EDITOR='mvim -f', per the tip from the FAQ for making it work with Git:
How can I use MacVim to edit Git commit messages?
Add the following line to the file ~/.profile:
export EDITOR='mvim -f -c "au VimLeave * !open -a Terminal"'
The last part ensures that Terminal gets focus again after closing the commit message. (Note that you need to put the mvim script in your path for this to work.)
If you have multiple SCMs on a machine (e.g. you have to work with Subversion and Mercurial, as I do), you can differentiate the editor by using HGEDITOR instead of the more generic EDITOR env. For example, I have the following environment variables set up:
export HGEDITOR='mvim -f -c "au VimLeave * !open -a Terminal"'
export SVN_EDITOR='mvim -f -c "au VimLeave * !open -a Terminal"'
In this case it's sort of pointless because the configuration is the same, but this is just to illustrate the point.
That also of course raises the point that you can set EDITOR and get that as the default for your various applications that use that, then override it with an application-specific variable for those apps that need something different. I tend to use the app-specific variables just to be... thorough, I guess (some might call it something else :).
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.)
I'm trying to get a git commit email hook running using Git on Windows. I'm sure I've got my copy of contrib/hooks/post-receive-email (placed in the project's .git/hooks/post-commit) script messed up, or I'm missing an important node in my config, but I don't know where I would see any error messages.
Would they be echoed to stdout when I commit using a shell? Is there some flag I would need to set or pass to git commit to see them (I tried -v with no apparent effect)?
EDIT
Here are the repo-specific config vals I've added:
sendemail.smtpserver=smtp.mycompany.com
hooks.mailinglist=me#domain.com
UPDATE
The overall problem is that git's built-in mail doesn't work on windows (which makes perfect sense, of course), but at least now I know where to look for output from my hacking attempts.
Are you sure the hook is actually being executed? (Make sure it's executable!) The post-commit hook is run in the same way as git-commit, so if you commit from a shell, you should see the output of all the commit-related hooks along with the output of git-commit itself in that terminal.