0

我有以下情况:我从分支 DEV 创建了分支 A 来开发新功能。其他人从 DEV 创建了分支 B,并从 A 中提取了我的代码。不幸的是,功能 A 和 B 是如此相关,以至于我也不得不从 B 拉到 A。现在我想做代码审查,但是当我这样做时,B 的变化也可见。有没有办法从 A 创建新分支,仅显示我与 A 或 DEV 相比的更改,或者是否有任何其他解决方案可以解决这个问题?我试图检查特定的提交,但这似乎不是一个好的解决方案。

4

1 回答 1

0

我对这个问题有点困惑,因为听起来你在第一句话中就想要你想要的:

我从分支 DEV 创建了分支 A

如果您因为需要分支中的代码而无法使用它B,那么创建新分支将无济于事。您可以获取两者所需的代码AB为此执行单独的拉取请求,然后A两者B都可以从那里分支,这将隔离它们各自在自己的 PR 中的更改。

无论您希望您的分支是什么样子,我相信您的问题的答案围绕着实现分支基本上只是指向提交的指针。您可以将现有分支或新分支指向您希望的任何提交。有多种方法可以做到这一点,其中一些最常见的是:

# create a new branch which points to commit a1b2c3 (newer syntax)
git switch -c my-new-branch a1b2c3
# or older syntax
git checkout -b my-new-branch a1b2c3

# change an existing branch to point to commit a1b2c3
git switch my-existing-branch # checkout the branch if you haven't already
git reset --mixed a1b2c3 # note "--mixed" is the default, you can leave it out
# Note mixed mode will leave all the changes you had on that branch as pending.
# If you don't want them (or have committed them elsewhere) and are
# willing to remove them from your current branch
git reset --hard a1b2c3

# create a new branch pointing to whatever commit I'm on now (don't checkout)
git branch my-new-branch

# create a new branch pointing to a1b2c3 (don't checkout)
git branch my-new-branch a1b2c3

# another way to reset an existing branch to point to a1b2c3 (don't checkout)
git branch -f my-existing-branch a1b2c3 # -f means "force"

# another way to reset an existing branch and checkout (newer syntax)
git switch -C my-existing-branch a1b2c3
# (older syntax)
git checkout -B my-existing-branch a1b2c3
于 2022-02-16T20:04:28.143 回答