I am trying to learn how to write a git commit message on a linux terminal.
I am presented with the following options after I write my commit message.
Which is the first one I am supposed to choose?
> ^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos
^X Exit ^R Read File ^\ Replace ^U Uncut Text^T To Spell ^_ Go To Line
If I hit "write out" I get another list of options that I don't understand.
File Name to Write:$T_EDITMSG
^G Get Help M-D DOS Format M-A Append M-B Backup File
^C Cancel M-M Mac Format M-P Prepend ^T To Files
It's because git pick up nano as its default terminal editor, if you are not familiar with nano, you can config git to use another one.
The easiest way to write a git commit message in terminal is to use the -m option:
> git commit -m "your commit message"
But if you don't specify the -m option, git will bring you to an editor depends on the following rules
Git config option core.editor, local config goes first, then the global.
Local: git config core.editor vim, config resides in file $YOUR_REPO/.git/config
Global: git config --global core.editor vim, config resides in file $HOME/.gitconfig
Please refer to Git Configuration for details.
Environment variables $EDITOR or $VISUAL
export EDITOR=`which vim`
export VSUAL=`which emacs`
This is also the settings used by other tools when it needs an editor.
When you just type git commit it will open your default text editor, nano in your case. You should type your message and hit enter after ^O.
To commit without opening a text editor:
git commit -m 'Your commit message here'
If you want to change your default editor to something else, say vim, you can do it as follows:
git config --global core.editor "vim"
Also helpful from GentooWiki:
In nano's help texts the Ctrl is represented by a caret (^), so Ctrl + W is shown as ^W, and so on. The Alt key is represented by an M (from "Meta"), so Alt + W is shown as M-W.
I'm guessing OP uses WSL or is new to linux. I am using a Ubuntu kernel in VS code via the Windows Subsystem for Linux (WSL, as before). There typing git commit opens a nano editor to save the commit. At least on Windows, the command to save the commit is CTRL + S. I don't think that option appears in the editor, but it worked for me.
Related
When I clone a project, I did git status right away and some files appear edited.
I check with git diff . and all edited files have the same message: "warning: CRLF will be replaced by LF".
I didn't even open any files.
git checkout . didn't work.
How is this possible?
On Linux new line mark it is \n, and on Windows it is \r\n, so it looks like when you clone a repository, the operating system changes \r\n to \n and you see the difference
I'm learning how to use the Ubuntu CLI on Windows for executing things like git commands, and so far everything works smoothly. My only gripe however is that whenever an instance of ST3 opens for commit messages, a second tab opens and somewhat ruins the flow of things.
Originally, what I had done to set ST3 as the text editor was append the following line to the .gitconfig file:
[core]
editor = /mnt/c/Program\\ Files/Sublime\\ Text\\ 3/subl.exe `wslpath.sh -w $PWD/.git/COMMIT_EDITMSG` -nw
Note: "wslpath.sh -w" works like cygpath, for those familiar with Cygwin functions, in that it converts Unix formatted directories to work with Windows.
I want to prevent this additional tab from opening every time I commit a change, and only have the window for editing messages appear:
You're not supposed to add the path of the file to the command. Git will put it as an argument for the command on its own.
So `wslpath.sh -w $PWD/.git/COMMIT_EDITMSG` should not be part of the command set as core.editor.
Your command relies on opening file COMMIT_EDITMSG, which would not work correctly when git will try to open file for editing of a merge commit message, or interactive rebase todo file, or editing an annotated tag message, etc. The commit message is not the only place where editing is done through a file.
The additional tab (as in the screenshot) then seems to be coming from the fact that the file is actually listed in the resulting command two times: once from core.editor config variable and a second time by git commit.
Im using a windows system to push my changes to a git linux server, where users commit with macOS, could this be the problem of invalid diff changes? changes which are not changes are displayed as deleted and later on re-added as new somehow. im using sublime and also tryed netbeans with the same behaviour...
Windows and *nix based operating system use different line ending character in files. In your case you are adding the Windows Carriage return character in your file and on MacOSX they are removed.
On your Sublime you can change the line ending character on save to match the MacOSX's line ending . See is there a way to convert files line ending on saving. This way you will not see these changes.
You could also instruct git to automatically do the conversion with the core.autocrlf config. See GitHub dealing with line endings
GitHub suggests that you should make sure to only use \n as a newline character in git-handled repos. There's an option to auto-convert:
$ git config --global core.autocrlf true
Of course, this is said to convert crlf to lf, while you want to convert cr to lf. I hope this still works …
And then convert your files:
# Remove everything from the index
$ git rm --cached -r .
# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add
# Commit
$ git commit -m "Fix CRLF"
As Per Git Config Manual
core.autocrlf
Setting this variable to "true" is almost the same as setting the text
attribute to "auto" on all files except that text files are not
guaranteed to be normalized: files that contain CRLF in the repository
will not be touched. Use this setting if you want to have CRLF line
endings in your working directory even though the repository does not
have normalized line endings. This variable can be set to input, in
which case no output conversion is performed.
The remote repo has mixed cr/lf lineendings, thought it was unix, now i just set the original lineending if it happens again.
I typically use VIM for almost everything coding-related.
I have configured my environment so Subversion opens VIM to edit the commit message when I execute svn commit. If I close VIM without saving the commit message (eg: :qa!), it is discarded, and the commit operation is aborted.
If I save and close VIM, then the commit operation will commence.
If the commit fails, I have some SVN commit messages that appear to be saved in /tmp/ with file names like svn-**.tmp.
While writing the commit message in VIM, the commit message appears to have a file name of svn-commit.1.tmp. I would like to be able to recover this message for my next SVN commit. The typically use case is:
I attempt to commit; complete writing message in VIM
Commit fails
I resolve the issue (eg: svn update)
Now I want to attempt svn commit again with the previous message pre-loaded into VIM
Thank you for your help.
You could always use the -F option with svn commit, which uses a file to create the log message.
Whenever I commit with svn, I first create a log file:
vim log_file
Then I use the following to commit:
svn commit -F log_file --username blah
This has always worked great for me.
You could try something like this:
svn commit -F /tmp/svn-1.tmp
You can read more there: http://svnbook.red-bean.com/en/1.0/re06.html
When in your vim session, just read the contents of the old log file. This permits you to adapt the old message if necessary, and doesn't change the workflow radically.
svn commit
(opens vim session)
:r /tmp/svn-**.tmp
Another solution is to just do your commits from the command line with the -m flag. This typically has the last (failed) commit in the command history of the related shell.
svn commit -m "Here is my message"
(commit fails, and you resolve it)
(up arrow a few times, and rerun the commit)
Git will store a cached version of your commit message in .git/COMMIT_EDITMSG.
After a "failed" committing attempt, you could run the following to recover your commit message.
vim .git/COMMIT_EDITMSG
Quiet simply I am trying to add new files to my repository, my command goes like this:
svn add * --force
but this produces:
svn: File 'install/config.xml.php' has inconsistent newlines svn:
Inconsistent line ending style
The thing is that this file is not yet under version control, so when I try to propdel or anything similar it doesn't work.
I am sure this file is not under version control because svn status shows this:
? install/version
? install/config.xml.php
I have already enabled the autoprops in svn default config but this did not help.
Any ideas?
Btw: this is a server, so no GUI.
vim makes it easy to force line endings to entirely CRLF or entirely CR.
:set ff=unix
:wq
d2u, dtox, dos2unix, are some names for simple utilities that are often installed on systems to do this task. You could also use the standard tr(1) utility:
tr -d '\r' < input > output
While working on Windows OS use Notepad ++:
Edit -> EOL Conversion.
- Windows Format
- UNIX/OSX Format
- Old Mac Format
You have current format information in the status bar.