How do I apply changes on this editor? - windows

While using GIT on the console and cherry picking this editor appeared. And I don't know how to apply/send the changes and move on

To save changes and quit, type :wq
Vim and Vi have different modes you can edit in. This allows users to use the main part of the keyboard for shortcuts ;)
If you are struggling to make changes in the first place, you have to enter insert mode by pressing i, then make your changes. You then have to go back to command mode by pressing Esc, then you can save and quit with :wq.
I agree with the other answers that you should use a different editor, unless you want to commit to learning Vim. Vim is great for learning to edit code super efficiently, but it's quite tricky to get your head around at first.

nano is another user friendly editor .
Unfortunately, nano does not come with the Windows version of Git.
You need to install nano.
Before making your first commit, try running:
nano
in the terminal. The result should be a simple editor with instructions at the bottom of the screen; close/quit with ctrl-X. If that worked.
git config --global core.editor nano
will configure Git to use the nano editor. The commands to use the text editor (like copy, paste, quit, etc.) will be shown on the bottom of the screen

This is a editor which git will launch according your default editor configuration.
Commonly, it is determined by your EDITOR environment variables, or configured by the the following command
sudo update-alternatives --config editor
You can do what I mentioned above to check what this editor is, and set your favorite editor to substitute it. After you change your default editor configuration, you can avoid this editor be launched again.

Related

"Please enter a commit message for your changes"

This window drives me crazy
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
It pops up when I forget to put -m"[message]" after "git commit", and now when I'm experiment with "git revert" I've seen instructions on how to abort this, but what if I actually want to submit a commit message? How do I do that? Pressing enter doesn't work, so what does?
The first line before
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
is precisely there for adding your commit message.
You press i, and you enter insert mode. You can navigate around the text and insert what ever you want.
When done, press Esc. This makes you exit insert mode.
Next you have to press :wq, which means to write and quit.
This will save your commit message.
Git allows you to use an editor of your choice to enter a commit message. If you don't specify one, then the default editor is a system-specific default, usually vi, which is a modal editor coming from Unix. As the Git FAQ says:
If you haven’t specified an editor specifically for Git, it will by default use the editor you’ve configured using the VISUAL or EDITOR environment variables, or if neither is specified, the system default (which is usually vi). Since some people find vi difficult to use or prefer a different editor, it may be desirable to change the editor used.
(When I wrote this, it was rather tongue-in-cheek, since a great many people do find vi difficult to use because the editing paradigm differs from most other editors. “How to quit vim” is a common search topic.)
My recommendation here is to type Esc and then :wq (then Enter) to quit vi and then configure the editor of your choice instead using the core.editor option. The Git FAQ provides examples of how to do this properly. Once you've done that, you can attempt your commit or revert again.
If you don't have a preferred editor, nano is a relatively simple editor that I can recommend for this case. I don't believe it's shipped with Git for Windows, though, so you'll need to download it separately.
If you do want to learn to use vi, then I'd recommend the vimtutor program, which comes with Vim (which is the most common vi editor and the option shipped with Git for Windows) that will teach you how to use it properly.
Your git is configured to use vi as a text editor (it is also the editor you will get if nothing else is defined).
You can change this editor to something else, for example :
you can use Notepad++ :
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
or Visual Studio Code :
git config --global core.editor "code --wait"
or any text editor you like : just check the command line options you have to pass to your editor

Vim on windows works weirdly when using it as git editor

When I'm using git and running any command which intends to open an editor (like git commit or git rebase -i) it opens up vim as expected in powershell but it behaves very strangely.
If i press <Ctrl + Right arrow> it erases a lot of content in the file and turns insert mode on but it should advance the cursor to the end of the next word keeping the current mode
If i open COMMIT_EDITMSG in another terminal with powershell and proceed with E (Forcing it not to use swap) it works just fine. I tried different terminal emulators like cmd and powershell terminal but it works the same (weird) way in all of them
Fixed it using neovim instead of vim
Note that it also act strangely when leaving vim, displaying the commit message poorly:
This is followed by microsoft/terminal issue 9359, and mentioned in the latest Git For Windows release 2.34: check if Git 2.34 would behave better with vim in your case.

How do I save git commit message under Powershell and nano ? (Ctrl+O doesn't work)

I'm on Windows. After git commit, I entered a message.
Then I tried Ctrl+O to save but it doesn't work (I guess I'm on nano, am I mistaken?).
Nano was added as a choice in 2017 with Git For Windows, because of issue 1224: "Add nano as a choice of editor(s) for git-commit because vim increases what we have to tell to beginners" (!)
But the editor by default remains "vim".
In your case, since you have modified the comment, ESC followed by :x is enough.
If this is nano, commands are Ctrl + X , then Enter (maybe multiple times depending on your conf)

How can I select text in git bash terminal in Windows 7 without mouse?

I am on Windows 7 and I have Git Bash at my disposal after installing Git for Windows.
I found mouse inconvenient to select-copy-paste in terminal window. What is the shortcut for text selection (like Shift+←, Shift+→ in Notepad editor)?
I have seen many irrelevant verbose replies to this question, but all, what I am looking for is just an appropriate shortcut (like Ctrl+Insert for Copy and Shift+Insert for Paste).
It is best to install a CMD enhancer like ConEmu.
From there, you can type "bash", and you will see in that Git bash session, that simple CTRL+C, Ctrl+V are enough for copy/paste.
And for selecting the text (in a ConEmu session), Shift+←, Shift+→ works too. For W7 or W10.

Closing a Terminal File

I'm working on Git Immersion lab 8. enter link description here
I ran "git commit" and it opened the editor. I understand how to write on the editor, but once I am done what do I do? How do I save and close this editor while maintaining my terminal work?
Thanks!
my current terminal
You appear to be in vim and are in insert mode.
To save and close, you have to get out of insert mode. Hit the 'escape' key (or control-[, which I personally like since I don't have to pull my fingers away from the keyboard. I'm not currently at a mac, so I'm not sure if it's control-[ or command-[ in your terminal).
Now type ':wq', without the quotes. Don't forget the colon. This is a vim command which will (w)rite and (q)uit.
I believe git has opened this file for you as a temp file, and once you've finished writing to it, git will use that file automatically for your commit message. No worries about where to save it.

Resources