在没有丢失变化的情况下合并上游的正确方法是什么? [英] What is the correct way to merge upstream without losing changes?

查看:90
本文介绍了在没有丢失变化的情况下合并上游的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



几个月前,我开始在一个repo分支上进行开发。我做了一些改变。我正准备将我的代码作为拉取请求重新发送给主人,但我意识到在此期间发生了不少变化...... $ b 因此,按照Github上的说明在拉入上游变更下试用:

  $ git remote add upstream ...#savon / httpi 
$ git fetch upstream
$ git merge upstream / master
$ git push origin / master#coldnebo / httpi

然而,现在我的叉子是宁乱。我仍然是一个使用git的新手,所以不要试图猜测术语是什么,我只会告诉你我得到了什么以及我的期望:



是我想要的差异。有没有什么方法可以进行rebase / revert,并在不丢失我的变化的情况下执行此操作?



乱七八糟的东西。



也许 git pull 会更好吗?

这并不是很多变化,所以如果它不可恢复,我总是可以手动比较和重新调整它,但我正在寻找正确的方式来做到这一点。

,如果你的repo是fubar,那么这里的步骤可以恢复:

  $ git remote update#确保原点和上游都达到date 
$ git checkout master
$ git branch my_changes#只是为了确保我的东西不会丢失
$ git reset --hard upstream / master
$ git status
#在分支ma上ster
#您的分支由8次提交支持'origin / master',并且可以进行快速转发。

忽略快速垃圾,它不会帮助你,只是重置

$ pre $ code $ git push origin + master#现在,fork匹配upstream / master

 

$ git diff --no-ext-diff - 无前缀master..my_changes> patchfile
$ patch -p0< patchfile#将patchfile应用于
$ git diff#以便直观地验证补丁。
$ rm patchfile#清理
$ rake spec#验证它是否真的有效。
$ git add。
$ git status#double triple verify
$ git commit。
$ git push origin master

我试图做rebase,但它一直说没有改变,并没有要求我检查什么?我很确定我不明白这里发生了什么事,这就是为什么我发布我的斗争,所以有人可以解释我如何能够避免这个混乱,并从A到B更优雅,现在它已完全记录。我很乐意将这一切归咎于缺乏经验,但我认为拉动变化应该是git中的一个非常普遍的事情 - 我必须错过一些东西。


I'm in a bit of a pickle.

I started development on a fork of a repo a few months ago. I made some changes. I was about to push my code back to the master as a pull request, but I realized there were quite a few changes in the meantime...

So, following the instructions at Github under "Pull in Upstream Changes" I tried:

$ git remote add upstream ...  # savon/httpi
$ git fetch upstream
$ git merge upstream/master
$ git push origin/master       # coldnebo/httpi

However, now my fork is rather messy. I'm still rather a novice with git, so instead of trying to guess what the terminology is I'll simply show you what I got and what I expected:

This is the diff I want. Is there any way to rebase/revert and do this without losing my changes?

what a mess.

maybe git pull would have been better?

It's not many changes, so if it's unrecoverable I can always manually diff and remaster it, but I'm looking for the "right way" to do this in the future.

解决方案

Ok, if your repo is fubar, then here's steps to recover:

$ git remote update     # make sure origin and upstream are up to date
$ git checkout master
$ git branch my_changes   # just to make sure my stuff isn't lost
$ git reset --hard upstream/master
$ git status
# On branch master
# Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
#

Ignore that fast-forward crap, it won't help you, just reset the master.

$ git push origin +master   # now, fork matches upstream/master

Now, how to recover the previous work so it's reviewable?

$ git diff --no-ext-diff --no-prefix master..my_changes > patchfile
$ patch -p0 < patchfile   # apply the patchfile to master
$ git diff     # to verify patch visually.
$ rm patchfile   # clean up
$ rake spec      # verify that it really works.
$ git add .
$ git status     # double triple verify
$ git commit .
$ git push origin master

That sucked. I tried doing rebase, but it kept saying "no changes" and didn't ask me to check anything in? I'm pretty sure I don't understand what's going on here, which is why I posted my struggle so someone can explain how I could have avoided this mess and gotten from A to B more elegantly now that it's fully documented. I'm willing to chalk this up to git inexperience, but I figure that pulling changes should be a really common thing in git -- I must be missing something.

这篇关于在没有丢失变化的情况下合并上游的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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