git重置本地存储库分支,就像远程存储库分支(Myremote分支)一样

发布于 2025-02-01 20:11:37 字数 392 浏览 3 评论 0原文

我正在尝试使用git做一些事情。

我有以下命令来获取和“清洁”我当前的分支,并将其(我当前的分支)与远程分支原始/主人完全相同:

  git fetch
  git reset --hard origin/master

这在工作。

现在,我想让我的当前分支与名为Myremotebranch的远程分支完全相同。 这是,我不想使我的当前分支与Origin/Master相同,而是想做与Myremotebranch(远程分支)相同的当前分支。

通过:

git fetch
git reset --hard origin/myremotebranch

我可以做到吗? (使我当前的本地分支就像远程分支一样?

I am trying to do some stuff using git.

I had the following commands to fetch and to "clean" my current branch and to make it (my current branch) exactly the same as the remote branch origin/master :

  git fetch
  git reset --hard origin/master

This is working.

Now I'd like to make my current branch exactly the same as remote branch named myremotebranch.
This is, instead of making my current branch the same as origin/master, I'd like to do my current branch the same as myremotebranch (remote branch).

By doing:

git fetch
git reset --hard origin/myremotebranch

Can I accomplish this? (make my current local branch just like remote remotebranch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2025-02-08 20:11:37

是的,您的重置命令将正如您描述的。但是,您无需拥有本地分支即可转移到另一个提交。您可以直接查看提交:

git checkout origin/master
git checkout origin/myremotebranch

这将使您进入独立的头状态。无需始终重置分支。

Yes, your reset commands will work as you describe. But you don't need to have a local branch to move to a different commit. You can check out commits directly:

git checkout origin/master
git checkout origin/myremotebranch

This will get you into detached HEAD state. No need to have a branch to be reset all the time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文