git:“更新被拒绝,因为您当前分支的提示在后面......”但是如何查看差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45293263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git: "Updates were rejected because the tip of your current branch is behind.." but how to see differences?
提问by transient_loop
I just finished working on a piece of code. Wanted to push and got the already famous:
我刚刚完成了一段代码。想推并得到已经出名的:
hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.
提示:更新被拒绝,因为您当前分支的提示在提示后面:它的远程副本。在再次推送之前集成远程更改(例如提示:'git pull ...')。
Now I've seen this question posted several times here, e.g.
现在我已经在这里多次看到这个问题,例如
更新被拒绝,因为您当前分支的提示在提示后面:它的远程副本。集成远程更改(例如
Updates were rejected because the tip of your current branch is behind
According to the specific case, the solution is either to
根据具体情况,解决办法是
git pull
, so the remote changes are mergedon to my local work, ORgit push -f
, a force push to update the remote (origin) branch.
git pull
,因此远程更改会合并到我的本地工作中,或者git push -f
,强制推送更新远程(源)分支。
Now, it has been a while I haven't worked on this branch. I don't necessarily want to mergethe remote changes onto my current work! Nor do I know if I can safely forcethe update on the origin branch...
现在,我已经有一段时间没有在这个分支上工作了。我不一定要将远程更改合并到我当前的工作中!我也不知道我是否可以安全地在源分支上强制更新......
How can I just see the differences and decide which is best for my case?
我如何才能看到差异并决定哪个最适合我的情况?
采纳答案by Ben
in order to see the differences, first you need to fetch the commits from the origin repository:
为了查看差异,首先您需要从原始存储库中获取提交:
git fetch origin
git fetch origin
Now you can see the diffs (Assuming you are on the master branch)
git diff HEAD..origin/master
现在你可以看到差异(假设你在主分支上)
git diff HEAD..origin/master
Now you are armed with the knowledge you seek to decide to merge
or rebase
before push
ing your changes.
现在,您已经掌握了决定更改merge
或更改更改rebase
之前的知识push
。
回答by djb
I had this happen to me recently when I created a new branch with git checkout -b feature/abc
, committed some changes, and then tried git push --set-upstream origin feature/abc
it to create a pull request for review. The error occurred because the remote branch already existed when I thought I was defining the branch locally. Deleting the remote branch resolved the issue and my push succeeded.
我最近这发生在我身上时,我创建了一个新的分支git checkout -b feature/abc
,犯了一些更改,然后尝试git push --set-upstream origin feature/abc
它来创建pull请求。发生错误是因为当我认为我在本地定义分支时远程分支已经存在。删除远程分支解决了问题,我的推送成功了。
回答by max630
If you mean to discard your local changesyou should run git reset --hard @{u}
. Note again this is irreversible action wrt some data, so be sure before running it. Here's how:
如果您打算放弃您的本地更改,您应该运行git reset --hard @{u}
. 再次注意,这是写入一些数据的不可逆操作,因此在运行之前请务必确保。就是这样:
To review which local commits you currently have you can use git log HEAD --not --remotes
, to compare to any remote branch or git log @{u}..HEAD
to see differences specific to the tracked branch.
要查看您当前拥有的本地提交,您可以使用git log HEAD --not --remotes
,与任何远程分支进行比较或git log @{u}..HEAD
查看特定于跟踪分支的差异。
To see the actual diff which you have committed locally, run git diff @{u}...
. This will ignore remote progress, and show only your changes.
要查看您在本地提交的实际差异,请运行git diff @{u}...
. 这将忽略远程进度,并仅显示您的更改。
To see uncommitted changes, run git diff HEAD
.
要查看未提交的更改,请运行git diff HEAD
.
PS: You should run first git fetch origin
or git remote update
to update the tracking references.
PS:您应该先运行git fetch origin
或git remote update
更新跟踪引用。