简体   繁体   English

在GitHub上提交PR时如何清除提交历史记录?

[英]How to clear out commit history when submiting a PR on GitHub?

I'm new to Git. 我是Git的新手。 On GitHub, I forked a third-party project to make contributions to. 在GitHub上,我分叉了一个第三方项目来做出贡献。 Every time new PRs are merged to its master, I have to update my fork to stay current. 每次将新的PR合并到其主节点时,我都必须更新我的fork以保持最新状态。 On the home page of my forked repository, I click New pull request , swap base and head forks, create a new PR, and merge it to my own copy. 在我的分叉存储库的主页上,单击“ New pull request ,交换基础叉和头部叉,创建新的PR,然后将其合并到我自己的副本中。

However, I noticed this is creating an increasingly large list of commits in the commit history every time I submit a PR. 但是,我注意到每次提交PR时,这都会在提交历史记录中创建越来越大的提交列表。 How do I consolidate all those commits into one before or after I submit a PR? 在提交PR之前或之后,如何将所有这些提交合并为一个? I'm using Visual Studio 2015. 我正在使用Visual Studio 2015。

I think I need to squash commits, but I don't know how to do that on VS. 我想我需要压缩提交,但是我不知道如何在VS上做到这一点。

You shouldn't squash or use pull requests, instead add the remote for the original repo to your project and then you can rebase on top of their latest code. 您不应该压榨或使用拉取请求,而应将原始存储库的遥控器添加到您的项目中,然后可以基于其最新代码进行重新构建。

 git remote add theirs https://www.github.com/original/project.git
 git fetch theirs

Now in Visual Studio (or from the command line) you can right click the theirs/master branch and select rebase onto . 现在,在Visual Studio中(或从命令行),您可以右键单击他们的/ master分支,然后选择rebase到 This will rewrite your local history and will replay your changes on top of their latest code. 这将重写您的本地历史记录,并在其最新代码之上重播您的更改。

It may be required to force push to your own github fork, because rebasing causes your local git commit-ids to change in some cases. 可能需要强制推送到您自己的github分支,因为在某些情况下,重新部署会导致本地git commit-id发生更改。 You may have to merge changes as the rebase takes place, since their latest version will be leading and your local commits will be replayed on top of the latest version of their code. 在重新设置基准时,您可能必须合并更改,因为它们的最新版本将成为主流,并且本地提交将在其代码的最新版本之上进行重放。

This process will give you the cleanest history that will include their latest changes. 此过程将为您提供最干净的历史记录,其中包括他们的最新更改。

If the rebase/force-push daunts you, it's also possible to do a normal merge from theirs/master into your local branch. 如果rebase / force-push令您望而却步,也可以将他们的/ master正常合并到您的本地分支中。 Make sure to fetch the latest changes from theirs after adding the remote and then you can right click their master branch in Visual Studio and select "Merge into" to merge their changes into your local working directory. 确保在添加远程对象后从他们的最新更改中获取最新的更改,然后可以在Visual Studio中右键单击其主分支,然后选择“合并到”以将其更改合并到本地工作目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM