git-仅将最上面的提交推送到服务器 [英] git - pushing only the top most commit to server

查看:64
本文介绍了git-仅将最上面的提交推送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下情况:

(1)由用户X合并补丁
(2)对其他代码进行了一些更改并提交.

(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?

推荐答案

第二修订版:

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^

现在git将处于合并代码的状态,并且您的更改未提交并准备再次进行.现在,您可以存储以下更改:

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"

现在,您可以从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"

这篇关于git-仅将最上面的提交推送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆