I just read Writing good commit messages and liked it a lot. The problem is, I prefer the command line (plain ole' git).
How can I add newlines and tabs to commit messages, so as to have a "summary line" and message body (which may consist of several paragraphs)?
Does GitHub support markdown in their commit messages? After reading "Shiny new commit styles" this doesn't seem possible
git automatically spawns your preferred $EDITOR to prompt for a commit message when you run git commit. So it may be as simple as leaving -m off of your git commit command
If git launches the wrong editor, or fails to launch an editor, try setting the EDITOR environment variable to your preferred editor:
export EDITOR=/usr/bin/vim
Or, to only change the editor used by git, you can set core.editor
git config --global core.editor /usr/bin/vim
Using an editor to compose a commit message this way has a couple of further advantages. Git populates the file you are editing with a summary of the files that were changed in the commit, which should help you write a better commit message. Also, vim (and other editors) support basic syntax highlighting for this kind of file, making it even easier.
For newline, just hit enter inside quotes, like this: git commit -m "Some headline <hit enter>. Also you can use your text editor to write commit messages.
Unfortunately no, e.g. this commit with markdown for example.
When creating a git commit, you can use -m multiple times and it will create multiple paragraphs.
To quote the man page
-m <msg>, --message=<msg>
Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs
Also, as mentioned before, if you leave out the -m option, then git will open an editor (set with a command like git config --global core.editor /usr/bin/vim) in which you can type your commit message.
Related
I've recently moved to Github (VS2017's built-in support) from Perforce for some individual projects. There is a feature in Perforce called "make writable" that allowed you to write to a file locally and then only submit it to the server by explicitly checking it out then submitting it.
This was used extensively for any binary files (.exe, etc) that only needed to be pushed very rarely but still needed to be written to.
Unfortunately from my limited experience with Github, it seems that all files are set to writable and are always marked as "changed", even exes. Is there a setting I can make or setup that allows Github to only mark a file as changed explicitly so I can't accidentally push an incomplete, broken, or debug .exe?
Updated answer: So, I forgot, if the file's tracked by Git at any point, then it gets a bit ugly. There are ways around this, but it isn't a single command to do this.
IF you want to do the .gitignore route, you can. But there's an added step (see below for first step). You have to, after each commit you do of the .exe file, run git rm --cached <filename>. This will remove the metadata around the file telling Git to track it. Once you do that, it won't show up anymore in the Changes list in the Visual Studio plugin (if you're on commandline it won't show up in git status). Then to add a file, you do what I mentioned below, which is to do the git add -f <filename>.
If instead, another way to do this, would be to run git update-index --assume-unchanged <filename>. This tells Git to ignore changes to the file. When you want to commit it, first run git update-index --no-assume-unchange <filename> and do your normal git add git commit workflow, then once you've committed it, run again the git update-index --assume-unchanged <filename> bit. It's messy, and honestly, I'd write a custom tool in VS to do this rather than relying on the built-in SCM tool in Visual Studio.
Original answer: Best way to do this (IMO, others will have their own opinion) is to add the files to your .gitignore. Then if/when you really want to commit them, do a git add -f <file> and then commit as normal.
Edit: Note that this is something everyone will have to do to avoid accidentally committing. A way around that is to commit your .gitignore as well so everyone has the same behavior.
Because of the changes in line endings, commits looks a lot bigger than they should be.
I have egit 4.6.1.201703071140
Before using egit, the command
git ls-files --eol
shows
i/mixed w/mixed attr/ somefile
then, after commit in Eclipse via git staging view, it is:
i/lf w/mixed attr/ somefile
Another example:
i/crlf w/crlf attr/ somefile2
becomes:
i/lf w/crlf attr/ somefile2
You can see egit is changing the first column to i/lf.
In GitHub you can use ?w=1 to dampen the noise, but how do I fix the problem itself?
git config
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.logallrefupdates=true
remote.origin.url=https://github.com/plutext/docx4j.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.master.rebase=false
According to https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration:
You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input.
You probably want to use false instead.
I have recently started using Microsoft's open-source Visual Studio Code IDE for developing web projects, shifting from Eclipse. I find VSCode highly intuitive and very simple to use.
But one feature I miss in VSCode is that the IDE's inability to remember commit messages (or have I not explored enough?!). Unlike Eclipse, which populates a dropdown list of historical commit messages, we have to manually enter commit messages in VSCode every time we commit our changes.
Is there any VSCode extension available for this purpose?
Can I make any entry in settings.json so that older commit messages
are retrieved automatically?
Any help would be highly appreciated.
VSCode 1.51 (Oct. 2020) does have a similar feature: Alt+Arrow Up:
Source Control input box saves commit message history
This addresses a feature request to navigate SCM commit history.
Press kb(scm.viewPreviousCommit) and kb(scm.viewNextCommit) to display the prior and next commits, respectively.
To move directly to the first and last position of the input box, press Alt in conjunction with the corresponding arrow key.
Build off of past commit messages and look back in the history without losing your drafted message.
No need for a separate extension or something like that. Git can handle this via commit templates and VSCode supports them already.
For example, assuming you have a unix-like and are in the root of your repository:
echo "My fancy commit message" > .mycommitmsg.txt
git config --local commit.template .mycommitmsg.txt
From there, VSC will automatically use the content of .mycommitmsg.txt.
Second step is to fill this message file with the content of your last commit. That can be achieved with Git hooks, in your case you want the post-commit hook.
Create/edit the file .git/hooks/post-commit with the following content:
#!/bin/sh
printf "`git log -1 --pretty=%s`" > .gitmessage.txt
Don't forget to make it executable:
chmod +x .git/hooks/post-commit
From there, everything should work as you described. The post-commit hook will automatically fill the message file with the content of your last message and VSC uses the new message as soon as you commit.
there's an extension that might be interesting for some people:
https://marketplace.visualstudio.com/items?itemName=JanBn.git-last-commit-message
I've just installed it before knowing about #kwood's answer, given that it helped me for a bit , I'm leaving this as a secondary option.
I'm new to git, and to GitHub. I'm using the GitHub for Windows program on Windows 7 64-bit. What I dislike is that when I create a new local repository, the initial change where the .gitattributes file is added is given a commit message containing an emoticon (seemingly chosen at random).
Here is a screencap of this problem in action: http://i.stack.imgur.com/sXVkv.gif
The emoticon in the above example was "confetti ball": http://i.stack.imgur.com/ePYdv.png
How do I prevent this emoticon? Or at least, how do I prevent the inital change from being automatically committed so that I have the opportunity to edit the commit message to remove the emoticon?
Even though I'd prefer to interact with the program's GUI, I have enough practice with the command line that if the fix for this issue requires using it, I'm comfortable with that.
Any help for this would be much appreciated.
git commit --amend
, then edit the commit message, then
git push origin master --force
(if the initial commit was also pushed behind your back)
I've recently started using mercurial (it's actually my first experience with version control) but having a very hard time wrapping my head around the concept. But thats another issue...
What I needed help with was adding files I have on my computer to a repository. I am currently trying to host my source on bitbucket and have tortoiseHG installed. I use Aptana as my IDE, and use the terminal in Aptana. I have a piece of PHP software written that I want to deploy. I added all the file to be committed via the terminal in Aptana. E.g. hg add index.php ...
After adding all the files I enttered hg commit and then a notepad popped up with all the files that were added to the queue to be committed. After closing out of there the terminal tells me the operation was aborted. This is the exact message I receive:
$ hg commit
abort: empty commit message
I am very new to this and I have no idea what is going on. What am I doing wrong?
You need to write commit message. After notepad popped out you see something like:
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: root#localhost
HG: branch 'default'
HG: changed src/messaging.js
You should leave message before lines starting with "HG:". For example:
Mercurial rocks!
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: root#localhost
HG: branch 'default'
HG: changed src/messaging.js
Another way to commit is to execute:
$ hg commit -m '<message here>'
If you have already TortoiseHG, you can get better and faster (I hope) results, if will use Workbench for all Mercurial-related tasks
Another idea is to have and use Aptana-Mercurial integration (Aptana Studio, if it matter)