简体   繁体   English

'git pull --rebase'之后看不到远程更改

[英]Not see remote changes after 'git pull --rebase'

I am trying to do a 'git pull --rebase', but I don't see any remote changes. 我正在尝试做一个'git pull --rebase',但我没有看到任何远程更改。 When I do a 'git status' I see ' Your branch is ahead of 'origin/master' by 12 commits.' 当我做'git status'时,我看到'你的分支在12次提交之前超过'origin / master'。

But I am current on my 'dev' branch, not master. 但我现在在我的'dev'分支上,而不是主人。

$ git branch
  master
* dev

And my 'dev' branch should track 'remotes/origin/dev'. 我的'dev'分支应该跟踪'remotes / origin / dev'。

All I want is I am working on 'dev' and I want to get remote changes on remote dev. 我想要的就是我正在开发'dev',我想在远程dev上进行远程更改。

But I did 'git pull --rebase' which some how pull remote 'master' changes to my 'dev' branch. 但我做了'git pull --rebase',其中一些如何将远程'master'更改为我的'dev'分支。

Can you pleases tell me how can I recover from my situation? 你能告诉我怎样才能从我的情况中恢复过来?

  1. remove the changes I pull in from remote 'master' branch mistakenly (after i did 'git pull --rebase') 删除我从远程'master'分支错误地引入的更改(在我执行'git pull --rebase'之后)

  2. pull in the changes on remote 'dev' branch on to my 'dev' branch. 将远程'dev'分支上的更改拉入我的'dev'分支。

Thank you. 谢谢。

It sounds as if your dev branch was originally based on origin/master instead of origin/dev , or somehow dev has been changed to track origin/master anyway. 听起来好像你的开发分支最初是基于origin/master而不是origin/dev ,或者不管怎么说dev已被改为跟踪origin/master You can check this with: 您可以通过以下方式检查:

git config branch.dev.merge

If that says refs/heads/master instead of refs/heads/dev you can change the upstream branch for your dev branch with: 如果说refs/heads/master而不是refs/heads/dev你可以改变dev分支的上游分支:

git checkout dev
git branch --set-upstream dev origin/dev

Then, to fix your branch, I would: 然后,为了修复你的分支,我会:

  1. Make sure that you're on the dev branch with git checkout dev 确保你使用git checkout devdev分支上
  2. Make sure that git status is clean 确保git status是干净的
  3. Create a branch to save where you were (for safety): git branch dev-wrongly-rebased 创建一个分支以保存您的位置(为了安全起见): git branch dev-wrongly-rebased
  4. Use git reflog to find the commit before you rebased onto origin/master 在重新定位到origin/master之前,使用git reflog查找提交
  5. Reset dev to that point git reset --hard COMMIT-BEFORE-BAD-REBASE dev重置为该点git reset --hard COMMIT-BEFORE-BAD-REBASE
  6. Finally, do git rebase origin/dev 最后,做git rebase origin/dev

My preference when rebasing is always to do it in two steps, eg: 我在变基时的偏好总是分两步进行,例如:

git fetch origin
git rebase origin/dev

... since I think that's less error-prone than git pull --rebase . ...因为我认为这比git pull --rebase更不容易出错。 I hope that's of some use. 我希望有一些用处。

You can move the commits on top of the correct remote branch with 您可以在正确的远程分支上移动提交

git rebase --preserve-merges --onto origin/dev start end

for a range of commits specified by start and end to be moved onto dev. 对于由start和end指定的一系列提交移动到dev。

Then, set up tracking properly. 然后,正确设置跟踪。 If you want, you can edit the .git/config file and compare how traking is set up for each branch all at once and ensure consistent behavior. 如果需要,可以编辑.git / config文件,并比较一次为每个分支设置的跟踪方式,并确保一致的行为。

From now on, of you are getting a new remote branch 从现在开始,您将获得一个新的远程分支

git checkout -t origin/branch_name

Or if you are pushing a new branch to the remote 或者,如果您要将新分支推送到远程

git push -u origin branch_name

These will set up traking as you want. 这些将根据您的需要设置跟踪。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM