How can I delete a commit?

417 views
Skip to first unread message

Vincent

unread,
Mar 12, 2008, 12:39:46 PM3/12/08
to gito...@googlegroups.com
Hi,

I've totally messed up - somehow, I pushed the git repository of one project onto the git repository of another, so now the most recent commit completely replaces the first project with the second. Being a Git newbie I have no idea how to resolve this - I've managed to revert my local repository to the commit before the last, but I don't know how to remove the latest commit hosted at Gitorious (http://gitorious.org/projects/vogel/repos/mainline/log/master).

Thanks in advance,
--
Vincent

Johan Sørensen

unread,
Mar 12, 2008, 4:18:04 PM3/12/08
to gito...@googlegroups.com
Hi Vincent,

I deleted your repository and re-created it, so that you can do a fresh push.


>
> Thanks in advance,
> --
> Vincent

Thanks
JS

Tim Harper

unread,
Mar 12, 2008, 4:18:34 PM3/12/08
to gito...@googlegroups.com
Hi Vincent,

You can do the following:

(backup your project and repository)
Checkout the branch you want to revert back
Delete your commit locally (git reset --hard HEAD^)
run "git push origin YOUR_BRANCH_NAME -f"

The -f will force the local branch to overwrite a remote branch.

Best,
Tim

Vincent

unread,
Mar 12, 2008, 5:03:12 PM3/12/08
to gito...@googlegroups.com

Thanks, however, I now get the following:

$ git push g...@gitorious.org:vogel/mainline.git
No refs in common and none specified; doing nothing.
fatal: The remote end hung up unexpectedly


I think I found out the cause of the problem in the first case: there is no .git directory in /var/www/vogel/ - instead, it seems to have been created in my home directory. Any idea how this has happened and how I can correct it?


>
> Thanks in advance,
> --
> Vincent

Thanks
JS
On 3/12/08, Tim Harper <timch...@gmail.com> wrote:
Hi Vincent,

You can do the following:

(backup your project and repository)
Checkout the branch you want to revert back
Delete your commit locally (git reset --hard HEAD^)
run "git push origin YOUR_BRANCH_NAME -f"

The -f will force the local branch to overwrite a remote branch.

Thanks, that would probably have solved it had the remote repo still been there, and it will definitely be helpful in the future, as I'm likely to mess it up again...

Best,
Tim




Thanks both,
--
Vincent

Tim Harper

unread,
Mar 12, 2008, 5:05:56 PM3/12/08
to gito...@googlegroups.com
The -f command should still help you

If you are trying to push master:

- make sure that the master branch exists locally, via 'git branch'

- command git to promote that branch to the remote, and overwrite anything that's there
git push origin master:master -f

Tim

Vincent

unread,
Mar 12, 2008, 5:28:57 PM3/12/08
to gito...@googlegroups.com
On 3/12/08, Tim Harper <timch...@gmail.com> wrote:
The -f command should still help you

If you are trying to push master:

- make sure that the master branch exists locally, via 'git branch'

I'm on the master branch:

$ git branch
* master


- command git to promote that branch to the remote, and overwrite anything that's there
git push origin master:master -f


$ git push origin master:master -f
error: src refspec -f does not match any.
error: dst refspec -f does not match any existing ref on the remote and does not start with refs/.

fatal: The remote end hung up unexpectedly
error: failed to push to 'g...@gitorious.org:vogel/mainline.git'

 
Note that I have followed these instructions in the past:

git remote add origin g...@gitorious.org:vogel/mainline.git
# to push the master branch to the origin remote we added above:
git push origin master
# after that you can just do:
git push

Tim



Thanks,

--
Vincent

Tim Harper

unread,
Mar 12, 2008, 5:36:14 PM3/12/08
to gito...@googlegroups.com
Ah, well I suppose it would help if I told you the params in the right order!

Try this:
git push -f origin master:master

Tim

Vincent

unread,
Mar 12, 2008, 6:01:46 PM3/12/08
to gito...@googlegroups.com
On 3/12/08, Tim Harper <timch...@gmail.com> wrote:
Ah, well I suppose it would help if I told you the params in the right order!

Try this:
git push -f origin master:master

Yes! Thanks a bunch! You made my day :)

Tim





--
Vincent

Vincent

unread,
Mar 12, 2008, 6:02:51 PM3/12/08
to gito...@googlegroups.com
Oh, by the way, do you happen to know why the .git dir is in my home directory and not in the project's dir?
--
Vincent

Tim Harper

unread,
Mar 12, 2008, 6:47:39 PM3/12/08
to gito...@googlegroups.com
eegad, no!  But whatever you do, don't type "git reset --hard" in your home directory, or "git clean -f", or anything like that.

Tim

Vincent

unread,
Mar 13, 2008, 12:45:51 PM3/13/08
to gito...@googlegroups.com


On 3/12/08, Tim Harper <timch...@gmail.com> wrote:
eegad, no!  But whatever you do, don't type "git reset --hard" in your home directory, or "git clean -f", or anything like that.

Tim


OK, thanks. I think I might've done a git init in my home directory accidentally. I suppose I'll rename the ~/.git folder and then see if I can clone the Gitorious project...

--
Vincent

gtcaz

unread,
Mar 17, 2008, 4:41:40 PM3/17/08
to Gitorious
I've also used git push --mirror to get things back on track.
Reply all
Reply to author
Forward
0 new messages