1

I have a situation where I:

(1) Merged a patch by user X
(2) Made some changes to some other code and committed.

Now I want to push my commit to the server. However, when I do

git push origin HEAD:refs/for/mybranch

I get an error regarding the patch that I merged, saying that I am not the author. Is there a way to do what I'm trying to accomplish? If not, is there a way to save my commit, then revert everything and push my commit back in?

DarezGhost
  • 59
  • 11

3 Answers3

1

Second revision:

git reset --soft HEAD^ (to undo your commit)
git stash (to stash away your changes)
git reset --soft HEAD^ (to undo the merge commit from X)
git stash (stash away X)
git stash apply stash@{1} (apply your changes)
git add . (add and commit and push ..)
git commit -m "some changes"
git push
git stash apply stash@{0}

Revised answer:

Ok, then you need to reset one step more back in the history:

git reset --soft HEAD^ (to undo your commit)
git stash (to stash away your changes)
git reset --hard HEAD^ (to undo the merge commit from X)
git stash apply (apply your changes)
git add . (add and commit and push ..)
git commit -m "some changes"
git push
git merge featureX (re merge the changes from X)

Original answer:

You could reset your head so your commit is moved to the index:

git reset --soft HEAD^

Now git will be in the state of the merged code and your changes uncommitted and ready to be staged again. Now you can stash these changes:

git stash save "stashing commit for changes from X"

Now you can push up the merged changes from X and after that apply the stash, add and commit:

git push
git stash apply
git add .
git commit -m "some stuff"
rtn
  • 127,556
  • 20
  • 111
  • 121
  • Interesting. However, I don't want to push X's change. That is just temporary code that I need to keep around, so I don't want to remove it completely either. I just don't want to push it up ... only push my commit. Any workaround for this? – DarezGhost Jun 01 '11 at 19:46
  • thanks, so it looks like I'll have to find that patch from X again :( This is what I was afraid of but I guess thats the only way to do it. – DarezGhost Jun 01 '11 at 20:05
  • Aha, nah this can be solved too :) Simply do --soft on the second reset as well, and stash away those changes. But when you apply your stash you need the stash id. (I forgot that you had problems finding X) – rtn Jun 01 '11 at 20:07
0

Why not just commit the patch, then convert your "changes to some other code" separately? Git is telling the truth, you are not the author of the patch, "user X" is.

Also, is there a reason you are doing this command:

git push origin HEAD:refs/for/mybranch

instead of just

git push origin mybranch
freedrull
  • 2,194
  • 4
  • 21
  • 33
  • the patch is already committed, but I don't want to push it up. I just want to keep it around and push up only my commit. – DarezGhost Jun 01 '11 at 19:48
0

Sounds like the repo has some hooks setup in it that prevent you from pushing any commits that you are not the author/commiter of.

You can attempt to cherry-pick the commit so that the commiter gets set to you. If that does not work then you need to ask whoever installed the repository hook because it breaks almost all git workflows because you will never be able to push a merge commit.

Arrowmaster
  • 9,143
  • 2
  • 28
  • 25