Generic git reset to default upstream HEAD

别等时光非礼了梦想. 提交于 2019-12-07 10:31:10

问题


Is there a syntax to reset to the current branch's default upstream HEAD?

Something like:

git checkout mybranch
git reset --hard origin/mybranch

where origin/mybranch can be generic for the current branch's upstream HEAD?


回答1:


The syntactic magic you want is part of a "revision specifier". These are documented in gitrevisions.

The string @{upstream} (abbreviation, @{u}), appended to a branch name, means "resolve the branch to its upstream". If you omit the branch name, git substitutes in HEAD, i.e., HEAD@{u}. This uses HEAD to find the current branch and then proceeds as if you had specified that.

So:

git reset --hard @{u}

will do the job (of course as with any git reset --hard, use this with care).

(In some shells you may have to quote the braces.)



来源:https://stackoverflow.com/questions/19961041/generic-git-reset-to-default-upstream-head

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!