git:如何重置难以理解

发布于 2024-12-05 06:31:15 字数 745 浏览 1 评论 0原文

我用 gerrit 做了一些工作,而用 gerrit 你只能得到提交的 refspec。比如:

refs/changes/01/15501/2

我该如何硬重置?

我试图表现得很好

[me@server code ((7deac0e...))]$ git reset --hard refs/changes/01/15501/2
fatal: ambiguous argument 'refs/changes/01/15501/2': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

这不是最好的错误消息,所以我再次尝试...

[me@server code ((7deac0e...))]$ git reset --hard -- refs/changes/01/15501/2
fatal: Cannot do hard reset with paths.

我不需要使用重置 --hard,但它在我的情况下效果很好。我的脚本在代码存储库中运行,但我不知道它处于什么状态。只有一个文件是可靠且不会更改的,即reset_to_gerrit脚本。

我告诉该脚本重置为某些引用规范,这将我的代码存储库放在一个我至少知道会发生什么的地方。原始状态和最终状态之间发生合并冲突的可能性非常高,硬重置应该避免所有这些。

Im doing some work with gerrit, and with gerrit you only get the refspec of a commit. Something like:

refs/changes/01/15501/2

How do I reset hard to this?

I tried to play nice

[me@server code ((7deac0e...))]$ git reset --hard refs/changes/01/15501/2
fatal: ambiguous argument 'refs/changes/01/15501/2': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

This was not the best error message, so I tried agian...

[me@server code ((7deac0e...))]$ git reset --hard -- refs/changes/01/15501/2
fatal: Cannot do hard reset with paths.

I dont need to use reset --hard, but it would work well in my situation. My script runs in the code repo, but I have no idea what state it is in. There is only one file which is reliable and doesn't change, which is the reset_to_gerrit script.

I tell that script to reset to some refspec, and that puts my code repo in a place that i atleast know what to expect. There is a very high possibility of merge conflicts between the original and final state, and reset hard should avoid all of that.

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

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

发布评论

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

评论(1

请恋爱 2024-12-12 06:31:15

您可以分两步完成。

  1. 首先获取更改
  2. 然后硬重置为 FETCH_HEAD

类似:

git fetch origin refs/changes/01/15501/2
git reset --hard FETCH_HEAD

You can do it in two steps.

  1. First fetch the change
  2. Then hard reset to FETCH_HEAD

Something like:

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