Top commit Questions

List of Tags
Laurie Young

I stupidly did a Git commit while half asleep, and wrote the totally wrong thing in the commit message. How do I change the commit message?

I have not yet pushed the commit to anyone.

Answered By: bueno ( 2708)
git commit --amend -m "New commit message"

Used to amend the tip of the current branch. Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch. The commit you create replaces the current tip -- if it was a merge, it will have the parents of the current tip as parents -- so the current top commit is discarded.

It is a rough equivalent for:

$ git reset --soft HEAD^
$ ... do something else to come up with the right tree ...
$ git commit -c ORIG_HEAD

but can be used to amend a merge commit.

Jeremy Ruten

Is there a way to edit the log message of a certain revision in Subversion? I accidentally wrote the wrong filename in my commit message which could be confusing later.

I've seen How do I edit an incorrect commit message in Git?, but the solution to that question doesn't seem to be similar for Subversion (according to svn help commit).

Answered By: Kamil Kisiel ( 184)

Essentially you have to have admin rights (directly or indirectly) to the repository to do this. You can either configure the repository to allow all users to do this, or you can modify the log message directly on the server.

See this part of the Subversion FAQ (emphasis mine):

Log messages are kept in the repository as properties attached to each revision. By default, the log message property (svn:log) cannot be edited once it is committed. That is because changes to revision properties (of which svn:log is one) cause the property's previous value to be permanently discarded, and Subversion tries to prevent you from doing this accidentally. However, there are a couple of ways to get Subversion to change a revision property.

The first way is for the repository administrator to enable revision property modifications. This is done by creating a hook called "pre-revprop-change" (see this section in the Subversion book for more details about how to do this). The "pre-revprop-change" hook has access to the old log message before it is changed, so it can preserve it in some way (for example, by sending an email). Once revision property modifications are enabled, you can change a revision's log message by passing the --revprop switch to svn propedit or svn propset, like either one of these:

$svn propedit -r N --revprop svn:log URL 
$svn propset -r N --revprop svn:log "new log message" URL 

where N is the revision number whose log message you wish to change, and URL is the location of the repository. If you run this command from within a working copy, you can leave off the URL.

The second way of changing a log message is to use svnadmin setlog. This must be done by referring to the repository's location on the filesystem. You cannot modify a remote repository using this command.

$ svnadmin setlog REPOS_PATH -r N FILE

where REPOS_PATH is the repository location, N is the revision number whose log message you wish to change, and FILE is a file containing the new log message. If the "pre-revprop-change" hook is not in place (or you want to bypass the hook script for some reason), you can also use the --bypass-hooks option. However, if you decide to use this option, be very careful. You may be bypassing such things as email notifications of the change, or backup systems that keep track of revision properties.


I cloned my repository with:

git clone ssh://xxxxx/xx.git 

but after I changed some files and add and commit them I want to push them to server:

git add xxx.php
git commit -m "TEST"
git push origin master

But the error I get back is:

error: src refspec master does not match any.
error: failed to push some refs to 'ssh://'

Answered By: user581625 ( 292)

Maybe you just need to commit. I ran into this when I did:

$~ mkdir repo && cd repo
$~ git remote add origin /path/to/origin.git
$~ git add .

Oops! Never committed!

$~ git push -u origin master
error: src refspec master does not match any.

All I had to do was:

$~ git commit -m 'initial commit'
$~ git push origin master



I would like to remove selected commit log entries from a linear commit tree, so that the entries do not show in the commit log.

My commit tree looks something like:


I would like to remove the B and C entries; So that they do not show in the commit log, but changes from A to D should be preserved. Maybe by introducing a single commit, so that B and C become BC and the tree looks like.


Or, ideally, after A comes D directly. D' representing changes from A to B, B to C and C to D.


Is this possible? if yes, how?

Some notes that might be helpful:
This is a fairly new project so has no branches as of now, hence no merges as well.

Side note: It's a personal project, so no, I'm not trying to destroy any evidence :)

Answered By: J.F. Sebastian ( 179)

git-rebase(1) does exactly that.

$ git rebase -i HEAD~5

git awsome-ness [git rebase --interactive] contains an example.

  1. Don't use git-rebase on public (remote) commits.
  2. Make sure your working directory is clean (commit or stash your current changes).
  3. Run the above command. It launches your $EDITOR.
  4. Replace pick before C and D by squash. It will meld C and D into B. If you want to delete a commit then just delete its line.

If you are lost, type:

$ git rebase --abort