“git rebase origin”与“git rebase origin/master”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5963597/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:53:08  来源:igfitidea点击:

"git rebase origin" vs."git rebase origin/master"

gitgit-rebase

提问by Dennis

I don't get the difference between git rebase originand git rebase origin/master. In my case I cloned a git repository twice. In the first clone I have to use git rebase originand in the other clone I must use git rebase origin/master.

我不明白之间的差别git rebase origingit rebase origin/master。就我而言,我克隆了 git 存储库两次。在git rebase origin我必须使用的第一个克隆中,在另一个克隆中我必须使用git rebase origin/master.

An example: http://paste.dennis-boldt.de/2011/05/11/git-rebase

一个例子:http: //paste.dennis-boldt.de/2011/05/11/git-rebase

回答by CharlesB

git rebase originmeans "rebase from the tracking branch of origin", while git rebase origin/mastermeans "rebase from the branch masterof origin"

git rebase origin装置“从跟踪分支底垫origin”,而git rebase origin/master指“从分支底垫masterorigin

You must have a tracking branch in ~/Desktop/test, which means that git rebase originknows which branch of originto rebase with. If no tracking branch exists (in the case of ~/Desktop/fallstudie), git doesn't know which branch of originit must take, and fails.

您必须在 中有一个跟踪分支~/Desktop/test,这意味着它git rebase origin知道要使用哪个分支origin进行变基。如果不存在跟踪分支(在 的情况下~/Desktop/fallstudie),git 不知道origin它必须采用哪个分支,并失败。

To fix this, you can make the branch track origin/masterwith:

要解决此问题,您可以使用以下命令制作分支轨道origin/master

git branch --set-upstream-to=origin/master 

Or, if masterisn't the currently checked-out branch:

或者,如果master不是当前签出的分支:

git branch --set-upstream-to=origin/master master

回答by Cascabel

Here's a better option:

这是一个更好的选择:

git remote set-head -a origin

From the documentation:

从文档:

With -a, the remote is queried to determine its HEAD, then $GIT_DIR/remotes//HEAD is set to the same branch. e.g., if the remote HEAD is pointed at next, "git remote set-head origin -a" will set $GIT_DIR/refs/remotes/origin/HEAD to refs/remotes/origin/next. This will only work if refs/remotes/origin/next already exists; if not it must be fetched first.

使用 -a,查询遥控器以确定其 HEAD,然后将 $GIT_DIR/remotes//HEAD 设置为同一分支。例如,如果远程 HEAD 指向 next,“git remote set-head origin -a”会将 $GIT_DIR/refs/remotes/origin/HEAD 设置为 refs/remotes/origin/next。这仅在 refs/remotes/origin/next 已经存在时才有效;如果不是,则必须先获取。

This has actually been around quite a while (since v1.6.3); not sure how I missed it!

这实际上已经有一段时间了(从 v1.6.3 开始);不知道我是怎么错过的!

回答by winterTTr

You can make a new file under [.git\refs\remotes\origin] with name "HEAD" and put content "ref: refs/remotes/origin/master" to it. This should solve your problem.

您可以在 [.git\refs\remotes\origin] 下创建一个名为“HEAD”的新文件,并将内容“ref: refs/remotes/origin/master”放入其中。这应该可以解决您的问题。

It seems that clone from an empty repos will lead to this. Maybe the empty repos do not have HEAD because no commit object exist.

似乎从空仓库中克隆会导致这种情况。也许空仓库没有 HEAD,因为不存在提交对象。

You can use the

您可以使用

git log --remotes --branches --oneline --decorate

git log --remotes --branches --oneline --decorate

to see the difference between each repository, while the "problem" one do not have "origin/HEAD"

查看每个存储库之间的差异,而“问题”没有“来源/头部”

Edit: Give a way using command line
You can also use git command line to do this, they have the same result

编辑:使用命令行给出一种方法
您也可以使用 git 命令行来执行此操作,它们具有相同的结果

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master

git符号参考参考/遥控器/原点/HEAD参考/遥控器/原点/主