git重置出错,远程存储库

发布于 2025-02-02 00:44:43 字数 577 浏览 4 评论 0原文

我犯了一个可怕的错误。

让我们开始当我拥有本地仓库(用于开发)和用于备份的远程裸仓库时开始:没有其他人使用此存储库,只有我。

让我们从A版本开始,从本地推到远程。 B版本也被推开(称其为BR,B遥控器),但后来我在本地返回版本,并在本地制作了一个版本。

我在本地完成了其他其他版本的服务。当我尝试推动它们时,我遇到了一些困难,因为远程分支在Br(A-≫ Br),而本地分支在D ...(a-> bl-> c-> d)。

我遵循了一些在线指南,并输入了命令: git重置srv/developbranch

现在,

  • 分支,本地一个和远程一个都指向br,
  • 一些不承诺的更改正在待处理,但它们似乎只是相对的c-> d更改,而不是全部更改,因为a,
  • 似乎都会删除BL之后的所有提交
  • 如果我检查树, ,我有A-> br(对于本地和远程分支) - >一些等待的更改,我也有A-> bl,而BL似乎处于独立状态(没有分支标签)

我希望做的事情: 像以前一样恢复本地和远程分支

: 罗伯托

I have made a terrible mistake.

Lets start when I had a local repo (used for developing), and a remote bare repo used for backup: no one else use this repository, just me.

Let's start from version A, pushed from local to remote.
Version B was also pushed (call it Br, B Remote), but later I get back to version A locally, and made a version Bl locally.

I have done serveral other versions locally; when I tryied to push them I have encountered some difficulties since remote branch was at Br (A->Br), and local branch was at D... (A->Bl->C->D).

I have followed some online guides and I typed the command:
git reset srv/DevelopBranch

Now,

  • both branches, local one and remote one are pointing to Br,
  • some uncommitted changes are pending but they seems only to be relative C->D changes, not all changes since A,
  • all commit after Bl seems to be erased
  • if I check the tree, I have A->Br (for both local and remote branch) -> some pending changes, I also have A->Bl, and Bl seems to be in a detached state (no branch label attached)

What I hope to do:
restore local and remote branches as before: A->Bl->C->D

Thank you so much...
Roberto

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

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

发布评论

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

评论(1

空名 2025-02-09 00:44:43

完全解决(非常感谢您的建议):

回顾,重置之前:

Local Branch    A -> Bl -> C -> D -> E
Remote Branch     \->Br

目标:

Local and remote A -> Bl -> C -> D -> E

我没有获得“目标”分支状态,而是进行了git重置,以恢复以下操作,

Local and remote A -> Br -> some uncommited changes

试图尽可能安全地工作,在首先,我制作了一个新的分支“ git分支救援者”,然后我保存了将每个修改的文件保存到该分支的文件(以下状态三中将省略此分支)。
让我们回到工作分支“ Git Checkout [Working_branch]”,实际上指向Br,B remoto。

返回A版本A,带有“ Git Reset -Hard Head^”,我有:

Local branch    A
Remote Branch    \-> Br

在日志文件中,我选择了从版本A到最后一个版本的所有SHA1 ID,每个行都具有“ proceding_sha1 this_ver_sha1 this_ver_sha1 this_ver_ver_ver_commit_title(example:a)” 。使用this_ver_sha1在当前分支hit git Merge上还原每个版本,例如第一种类型“ git merge [sha1_ver_blocal]”,然后重复

Local branch     A -> Bl
Remote branch     \-> Br

“ git merge [sha1_ver]”以还原版本C,然后d d,然后e ...我的情况与GIT重置之前的情况相同:

Local Branch    A -> Bl -> C -> D -> E
Remote Branch     \->Br

还有一个带有其他文件的额外分支,没有得到更好的识别。

好的,这解决了很多麻烦,但仍然缺少最后一步:从远程分支中删除BR并将本地分支复制到远程分支,如:

Local and remote Branch    A -> Bl -> C -> D -> E

编辑:

比我想象的要简单,我只需要做强制推动...这个覆盖远程分支与本地分支!!!

太好了,最后我终于得到了理想的结构:

Local and remote Branch    A -> Bl -> C -> D -> E

再次感谢您。

FULLY SOLVED (thank you a lot for your suggestion):

Recaps, before reset I had:

Local Branch    A -> Bl -> C -> D -> E
Remote Branch     \->Br

Target:

Local and remote A -> Bl -> C -> D -> E

Instead of getting the "target" branch status, i did a git reset obtaing something like the following

Local and remote A -> Br -> some uncommited changes

Trying to work as safe as possible, at first I made a new branch "git branch RescueVer", then I saved each modified file committing to this branch (this branch will be omitted in the following status three).
Let's get back to the working branch "git checkout [working_branch]" that actually points to Br, B Remoto.

Get back to version A with "git reset --hard Head^", I have:

Local branch    A
Remote Branch    \-> Br

In the log file I pick all the sha1 id from version A to the last ver, each rows has "preceding_sha1 this_ver_sha1 This_ver_commit_title(example: A)". Use this_ver_sha1 to restore each version on current branch whit git merge, for example first type "git merge [sha1_ver_Blocal]" and get

Local branch     A -> Bl
Remote branch     \-> Br

Repeat "git merge [sha1_ver]" to restore version C, then D, then E... At the end I had the same situation I had before git reset:

Local Branch    A -> Bl -> C -> D -> E
Remote Branch     \->Br

and an extra branch with some other files, not better identified.

Ok, this solves a lot of troubles, but still missing the last step: remove Br from Remote branch and duplicate local branch to remote one, as this:

Local and remote Branch    A -> Bl -> C -> D -> E

EDITED:

Simpler than I can imagine, I have to do no more than a forced push... this overwrites remote branch with local one!!!

Wonderful, doing this at the end I finally get the desired structure:

Local and remote Branch    A -> Bl -> C -> D -> E

Thank you again.

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