How do I enter the commit message in this bash pop-up? - bash

I want to merge a remote repository to a new repository on GitHub. I have tried the following bash commands:
git init
git commit --allow-empty -m "Initial dummy commit"
git remote add --fetch old_a <OldA repo URL>
git merge old_a/master --allow-unrelated-histories
After executing the last command, this screen pops up:
Here bash is asking me to enter a commit message. But typing appears to be prohibited everywhere except in the yellow line. Not only that, I can't even terminate this prompt if I want to go back to the command line. There seems no way to break out other than closing bash itself. So how do I proceed from here?
PS: I have already tried to change my default git editor to vim using the following commands:
git config --global core.editor vim
As well as,
export EDITOR="vim"
But both of these commands didn't work.

This is not an issue, all you need to do is
Press Insert Key and then Enter Key. This will allow you to type a message
Once you have done that Press Esace (Esc) then :wq to exit

Related

Always prompt for a stash message in git

I tend to stash changes without remembering why I stash them.
I do make it a point to git stash push -m most of the time, but if there's a fire drill or something else that knocks me out of flow, I may forget and lose time trying to recover.
Is there a way to imitate the behavior of git commit (minus the -m) for git stash where vim pops up and abandons the operation if the message is empty?
AFAIK there's no config option for this. You'll have to write an alias in your .gitconfig and train yourself to use it.
For example, I have two stash aliases git pop and git save. (You can see I didn't get the memo about git stash save being deprecated). These are both for convenience, and to change the default behavior to something I find more useful.
save = stash save -k -u
pop = stash pop
Unfortunately git stash push -m doesn't bring up an editor, if you need to write more than a few words to describe what you were doing consider a branch instead. We can fix this by writing a little shell function and passing the argument to -m using "$#" to ensure messages with spaces are a single argument.
savem = "!f() { git save -m \"$#\"; }; f"
Now you can write git savem 'remember to remember what this was'.
$ git savem 'remember to remember what this was'
Saved working directory and index state On issue/45: remember to remember what this was
And if you forget, you'll get the normal git-stash usage message. You can snazz up the alias to provide a custom usage message if you like.
$ git savem
usage: git stash list [<options>]
or: git stash show [<stash>]
...
To me it makes sense to consider using a branch for this. It seems like you want to keep the changes. Branches can be named so it’s easier to recall what was being worked on. These can be local or pushed to remote in case it wasn’t a drill.
$ git branch topic/wip
If you want continue work on master yo can do a
$ git checkout master
Not pretty but could be achieved using bash + vipe in moreutils
msg="$(< /dev/null vipe)";
[[ -z "$msg" ]] || git stash -m "$msg"

Weird terminal behavior with "git difftool"

When I try to use "git difftool", the terminal seems to enter a mode where hitting the "enter" key outputs ^M instead of accepting the default option:
$ git difftool --tool=tkdiff file
Viewing (1/1): 'file'
Launch 'tkdiff' [Y/n]: ^M^M^M^M^M^M^M^M
I can control-c out of it, but I can't get difftool to work.
"git diff" works like a charm.
I am struggling to Google for this problem.
I am running Ubuntu 14.04.2 LTS, my TERM is xterm, and my .gitconfig is very simple, it has nothing about output in it:
[user]
name = My Name
email = myemail#example.com
[alias]
co = checkout
How can I use "git difftool"?
Probably a terminal configuration problem rather than a git issue. Run stty sane to see if that helps or follow other instructions in this similar post: https://askubuntu.com/questions/441744/pressing-enter-produces-m-instead-of-a-newline

How does one disable Git's HTML help (on Windows)?

I installed Github for Windows which comes with the Git command line client, and whenever I forget a switch or something and want to use --help, instead of dumping to the console it's launching a browser. Is there a way to ask Git to dump the help to the console (as it does in most Unixen by default) instead of launching a browser?
In windows
git <command> -h
will write help to the terminal output
git <command> --help
will pop up a browser window
This is a frail workaround, but if you just want a quick usage summary, feed the git sub-command of your choice a deliberately bad option name. I tried "--halp". For example:
$ git stash --halp
error: unknown option for 'stash save': --halp
To provide a message, use git stash save -- '--halp'
usage: git core\git-stash list [<options>]
or: git core\git-stash show [<stash>]
or: git core\git-stash drop [-q|--quiet] [<stash>]
or: git core\git-stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git core\git-stash branch <branchname> [<stash>]
or: git core\git-stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]]
or: git core\git-stash clear
I can't say for sure that "halp" will always be rejected, but it seems to get the job done. Hopefully it'll never get interpreted as a usable parameter. This is probably better than random typing, for example, since you might randomly type in correct input.
For Linux systems you could set this with git config --global help.format <web|man|info>. Unfortunately the man pages are not part of the Git for Windows bundle so only 'web' works.

Is there a way to allow spaces in bash bang pattern (repeating last command)

I was wondering if there is a way to repeat a bash command with a subcommand separated by space. For example, if I enter several commands,
git add a.txt
git status
... other commands starting with git
git commit -m ""
and do:
!git
I will run the last git commit command again. My questions, is there a way to repeat the last command that contains a space, e.g. to repeat the last git status command?
I tried,
!git\ s
!"git s"
, but none works.
Try:
!?git s
The "!?string" event designator searches for the most recent command preceding the current position in the history list containing string.
Also you could use this to refer to the command n lines back:
!-n
In this case, you could hit CtrlR , type "git s" then hit Enter
Though related, but not exactly answering your question ...
Try adding the following two lines to your ~/.bashrc
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
FUNCTIONALITY (after you source ~/.bashrc or open a new terminal):
when you start typing i.e. "git" and hit the up or down arrow, it will search through your history completion to complete what's already on the line.
Reference
You can also use the fc bash builtin command:
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ git diff
usage: git diff [--no-index] <path> <path>
$ fc -s 'git s'
git status
fatal: Not a git repository (or any of the parent directories): .git
$

Add line break to git commit -m from command line on Windows

My company has a policy that all checkins to a particular project must follow a specific multi-line template for git commits. How can I most simply create a single commit message that has multiple lines from the command line in Windows?
This is almost exactly a duplicate of "Add line break to git commit -m from command line" except that this question is specific to Windows/cmd.exe, while that question is related to bash.
Either create a file that contains your commit message in the right format and use git commit -F <message_file>, after which you can continually edit and reuse that same file, or create a template file and use git commit -t <template_file> to open your editor with the pre-cooked template to be filled in. The second option can be made permanent by setting the commit.template configuration variable, so you don't need to use the -t ... bit on every commit. See the git commit manual page (git help commit, if your git is installed correctly, or search online) for more information.
You can create multiline commit message like this:
C:\> git commit -m "Line 1"^
More?
More? "Line 2"^
More?
More? "Line 3"
Note, that the circumflex character is only on odd lines.
git commit -m "Subject" -m "Description..."
You can also use interactive rebase and then reword for editing the commit's message.
Type git commit -m "doesnt really matter whats here" and then git rebase -i HEAD~1, replace pick with r or reword, save and then edit the message.

Resources