Edit: Regarding This question may already have an answer here:, note that the title of that question refers to undoing a commit, not a push. I don't think SO should be reinforcing the frequent confusion between the two within git. Also is a question with 22 different answers going to be the best reference?
I created a new project lambda
in a repository X, under the dev branch, then did git add
, git commit
and git push
.
Turns out it doesn't belong in that repository, but in repository Y, under its dev branch. Now people looking at X are seeing a bunch of stuff that doesn't belong.
How do I remove that push from X dev? Note that I don't want to remove the whole branch from X, just the bad push I did.
If it helps, everything is self contained in that project, no other projects were altered. Just deleting lambda project and any history of it would be okay too.
After searching, I think what I want to do is undo a git push. But I'm not sure I understand the solution.
git log
This is what git log
is telling me.
$ git log
commit 0c9ac8b157222995d3414b84e7ce1b3e1adf5560
Author: Clueless <clueless@initech.com>
Date: Fri Feb 14 10:01:38 2014 -0400
Initial commit of lambda.
commit bdd142c778f0c43141cf48d60e4ee0bef018e1c0
Author: Not Clueless <notclueless@initech.com>
Date: Thu Feb 13 12:50:39 2014 -0400
update red with latest and greatest
commit f1047816fa7b201de7f798e6026b8b29a1bf8f75
Author: Also Not Clueless <alsonotclueless@initech.com>
Date: Wed Feb 5 15:48:07 2014 -0400
update green with latest and greatest
etc...
So do I want to use?
git push -f origin 0c9ac8...:<???>
But don't I want to make bdd142...
be the origin? Also what do I specify for ??? ?
Diagrams
Perhaps a couple of diagrams might help:
What it looks like now:
X-repo
+---master-branch
|
+---dev-branch---+---red-project
| |
| +---green-project
| |
| +---blue-project
| |
| +---lambda-project <-- doesn't belong
|
+---other-branches
Y-repo
+---master-branch
|
+---dev-branch---+---alpha-project
|
+---beta-project
|
+---gamma-project
What it should look like:
X-repo
+---master-branch
|
+---dev-branch---+---red-project
| |
| +---green-project
| |
| +---blue-project
|
+---other-branches
Y-repo
+---master-branch
|
+---dev-branch---+---alpha-project
|
+---beta-project
|
+---gamma-project
|
+---lambda-project <-- belongs here