清理git分支的历史记录

清理git分支的历史记录,git,github,Git,Github,我有两个分支feature/foo和feature/foo clean history 两个分支都包含相同的源代码,没有区别,只是第一个分支的历史太长,第二个分支的历史很干净 由于AFAIK()无法更改github PR的源分支,因此我希望feature/foo具有与feature/foo clean history相同的干净历史 我怎样才能达到我想要的状态?你真正需要做的唯一一件事是删除“相同”的分支(git branch-d branch name),也许,从带有git checkout-b

我有两个分支
feature/foo
feature/foo clean history

两个分支都包含相同的源代码,没有区别,只是第一个分支的历史太长,第二个分支的历史很干净

由于AFAIK()无法更改github PR的源分支,因此我希望
feature/foo
具有与
feature/foo clean history
相同的干净历史


我怎样才能达到我想要的状态?

你真正需要做的唯一一件事是删除“相同”的分支(git branch-d branch name),也许,从带有git checkout-b新分支名称的干净分支中创建一个同名分支,在分支中,你想要“克隆”。。
如果您想远程删除分支,请使用git push origin--delete remoteBranchName

您真正需要做的唯一一件事是删除“same”分支(git branch-d branch name),并且,也许可以从带有git checkout-b新分支名称的干净分支中创建一个同名分支,在分支中,您想要“克隆”。。 如果要远程删除分支,请使用git push origin--delete remoteBranchName

我希望feature/foo具有与feature/foo干净历史相同的干净历史

我希望feature/foo具有与feature/foo干净历史相同的干净历史


这回答了你的问题吗?这回答了你的问题吗?
# Save changes and clear your working directory
git stash save

# Checkout the `feature/foo` branch
git checkout feature/foo 

# Reset to let `feature/foo` point the same commit than `feature/foo-clean-history`
git reset --soft feature/foo-clean-history

# Here you should have no changes in the staging area.
# If there are some, then the code in the 2 branches wasn't exactly the same,
# do what you think is good with these changes (i.e. commit or reset changes)

# Update remote `feature/foo` and so the PR
git push origin --force-with-lease