将 git parent 指针设置为不同的父级 [英] Setting git parent pointer to a different parent

查看:55
本文介绍了将 git parent 指针设置为不同的父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我过去有一个指向一个父级的提交,但我想更改它指向的父级,我将如何去做?

解决方案

使用 git rebase.这是 Git 中通用的进行提交并将其/它们放入不同的父级(基础)"命令.

一些需要了解的事情:

  1. 由于提交 SHA 涉及其父项,因此当您更改给定提交的父项时,其 SHA 将更改 - 其之后的 所有 提交的 SHA 也将更改(最近的它)在开发中.

  2. 如果您正在与其他人合作,并且您已经将有问题的提交公开推送到他们提取的位置,那么修改提交可能是一个坏主意™.这是由于 #1,因此其他用户的存储库在尝试找出由于您的 SHA 不再与他们的相同"提交匹配而发生的情况时会遇到混淆.(有关详细信息,请参阅链接手册页的从上游重新数据库恢复"部分.)

也就是说,如果您当前在一个分支上有一些要移动到新父级的提交,它看起来像这样:

git rebase --onto <老父母>

这会将当前分支中之后

的所有内容移动到之上相反.

If I have a commit in the past that points to one parent, but I want to change the parent that it points to, how would I go about doing that?

解决方案

Using git rebase. It's the generic "take commit(s) and plop it/them on a different parent (base)" command in Git.

Some things to know, however:

  1. Since commit SHAs involve their parents, when you change the parent of a given commit, its SHA will change - as will the SHAs of all commits which come after it (more recent than it) in the line of development.

  2. If you're working with other people, and you've already pushed the commit in question public to where they've pulled it, modifying the commit is probably a Bad Idea™. This is due to #1, and thus the resulting confusion the other users' repositories will encounter when trying to figure out what happened due to your SHAs no longer matching theirs for the "same" commits. (See the "RECOVERING FROM UPSTREAM REBASE" section of the linked man page for details.)

That said, if you're currently on a branch with some commits that you want to move to a new parent, it'd look something like this:

git rebase --onto <new-parent> <old-parent>

That will move everything after <old-parent> in the current branch to sit on top of <new-parent> instead.

这篇关于将 git parent 指针设置为不同的父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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