如何推送新的(重写)历史到远程存储库 [英] How to push new (rewritten) history to remote repository

查看:66
本文介绍了如何推送新的(重写)历史到远程存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个我想解决的开放式拉取请求,同时我想将包含2个特性的1个提交分成2个独立的提交。



Github仓库现在看起来像这样,其中fix是一个新的分支:

  master ccc 
\
修复cccc

我从修复程序创建了一个拉取请求。



我想将修复中的最后一个提交更改为本地存储库中的2个提交,如下所示:

  master ccc 
\
fix cccnn

其中nn是我的2个新提交。 p>

为了达到这一点,我做了这个:

  1。 git rebase -i HEAD〜2 
2.将我最后一个提交行更改为edit,保存并关闭文件
3. git reset HEAD ^
4. git stash save
5.在第一次提交
时删除了我不想要的更改6. git commit -mcommit a-a
7. git stash apply
8. git commit -m commit b

所以现在我有2个提交的方式。问题是我发现了一个错误,最终在pull请求中。由于我已经推送到远程仓库,它不会接受我的新提交(因为原来的提交失踪)。



我运行:

  git push origin fix --dry-run 

,我得到以下信息:

 至git@github.com:< UserName> / < Repository> .git 
! [rejected] fix - >修复(非快进)
错误:未能将一些文件推送到'git@github.com:< UserName> /< Repository> .git'

我已经看到其他帖子建议在再次推回前从原点拉出我的更改,但是不会基本上将我的2次提交重置为一次?

理想情况下,我想要做的是将相同的提交ID分配给最后一次提交,以便它可以按原样替换当前提交ID。有没有办法做到这一点? (请注意,我没有使用 - hard )运行 git reset
<当遇到这个问题时,强制推送对我有效:

 <$> 

c $ c> git push - 强制源定义


Basically, I have an open pull request that I want to fix and at the same time I want to make 1 commit that contains 2 features into 2 seperate commits.

Github repository now looks like this where fix is a new branch:

master c-c-c
            \
     fix c-c-c-c

I created a pull request from fix.

I wanted to change the last commit in fix into 2 commits in my local repository as follows:

master c-c-c
            \
     fix c-c-c-n-n

where n-n are my 2 new commits.

To get to this point locally, I did this:

1. git rebase -i HEAD~2
2. Changed my last commit line to "edit", saved and closed the file
3. git reset HEAD^
4. git stash save
5. Removed the changes I don't want in the first commit
6. git commit -m "commit a" -a
7. git stash apply
8. git commit -m "commit b"

So now I have 2 commits the way I want. The problem is I found a bug that ended up in the pull request. Since I have already pushed to the remote repository, it won't accept my new commits (as the original one is now missing).

I run:

git push origin fix --dry-run

and I get the message:

To git@github.com:<UserName>/<Repository>.git
! [rejected]        fix -> fix (non-fast-forward)
error: failed to push some refs to 'git@github.com:<UserName>/<Repository>.git'

I have seen other posts suggest to pull my changes from origin before pushing back again, but won't that basically reset my 2 commits back into the one?

Ideally, what I would like to do is assign the same commit ID to the last commit so it can replace the current one as is. Is there a way to do that? (Note that I didn't run git reset with --hard)

解决方案

When faced with that problem, a force push has worked for me:

git push --force origin fix

这篇关于如何推送新的(重写)历史到远程存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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