如何在特定提交上创建分支点? [英] How do I make a branch point at a specific commit?

查看:74
本文介绍了如何在特定提交上创建分支点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,我知道分支是指向提交的指针.

In Git, I understand that a branch is a pointer to a commit.

如何将特定分支指向特定提交?假设我想将master指向1258f0d0aae...,该怎么做?

How do I make a specific branch point to a specific commit? Say I want to make master point at 1258f0d0aae..., how do I do that?

推荐答案

您可以这样将master指向1258f0d0aae:

git checkout master
git reset --hard 1258f0d0aae

但是您在执行此操作时必须小心.它很可能会重写该分支的历史记录.如果您已经发布了该出版物,而其他人正在该分支上工作,那将会造成问题.

But you have to be careful about doing this. It may well rewrite the history of that branch. That would create problems if you have published it and other people are working on the branch.

此外,git reset --hard命令将丢弃所有未提交的更改(即,仅在您的工作树或索引中的那些更改).

Also, the git reset --hard command will throw away any uncommitted changes (i.e. those just in your working tree or the index).

您还可以通过以下方式强制更新分支:

You can also force an update to a branch with:

git branch -f master 1258f0d0aae

...但是如果您当时在master上,git不会让您这样做.

... but git won't let you do that if you're on master at the time.

这篇关于如何在特定提交上创建分支点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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