如何从拉动请求中删除/清除旧提交历史记录?

发布于 2025-01-17 10:12:52 字数 224 浏览 2 评论 0原文

在拉取请求并从远程原始分支合并到上游之后,我从远程删除了该分支,但我重命名了本地分支并继续处理它(我认为这就是我搞砸的原因)。当我将此本地分支提交到远程源并向上游发出拉取请求时,我对第一个拉取请求的提交也出现了。

  1. 有没有办法从此拉取请求中删除旧的提交历史记录?

  2. 或者我必须关闭此拉取请求并将本地分支重新设置为上游,然后再执行另一个拉取请求?

After a pull request and merge from my remote origin branch to upstream, I deleted the branch from my remote, but I rename the local branch and keep working on it (which I think is the reason why I messed up). When I commit this local branch to remote origin and did a pull request to the upstream, my commits of the first pull request also appeared.

  1. Are there ways to remove the old commit history from this pull request?

  2. Or I have to close this pull request and rebase the local branch to the upstream before doing another pull request?

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

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

发布评论

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

评论(2

桃气十足 2025-01-24 10:12:52

如果您已经从旧分支(此处为 PR 分支)开始工作,请将提交移至上游目标分支(例如原始存储库 main 分支)的顶部,

cd /path/to/repo
git remote add upstream https://github.com/<origina>/<repo>
git fetch upstream

您可以从

   old PR
     |
--x--x--Y--y--y (newBranch)
      \
       m--m--m (upstream/main, updated by the fetch)

快速变基开始:

git switch myNewBranch
git rebase --onto upstream/main firstNewCommit^1 myNewBranch

这给出了:

   old PR
     |
--x--x
      \
       m--m--m (upstream/main)
              \
               Y'--y'--y' (newBranch)

git push --force ,并且您的新 PR 会以更短的历史记录进行更新。

If you have started working from an old branch (here a PR one), move your commits on top of the upstream target branch (for instance, the original repo main branch)

cd /path/to/repo
git remote add upstream https://github.com/<origina>/<repo>
git fetch upstream

You start from

   old PR
     |
--x--x--Y--y--y (newBranch)
      \
       m--m--m (upstream/main, updated by the fetch)

A quick rebase:

git switch myNewBranch
git rebase --onto upstream/main firstNewCommit^1 myNewBranch

That gives:

   old PR
     |
--x--x
      \
       m--m--m (upstream/main)
              \
               Y'--y'--y' (newBranch)

A git push --force and your new PR is updated with a much shorter history.

携余温的黄昏 2025-01-24 10:12:52

如果您的更改尚未推动,则可以简单地使用

git reset --hard HEAD~1

,如果您已经推动了更改,则可以使用此命令

git push origin HEAD --force 

if your changes has not been pushed yet you can simply use

git reset --hard HEAD~1

Alternatively, if you have already pushed your changes you can use this command

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