How to squash commits in a Pull request

Shubham Sharma

I have a pull request on an Open-Source repository with one commit e.g., commit a. Now someone requested me to change some code in that commit. If I open that branch in my Android Studio and change the requested code and then If I commit again, there will be two commits. I want to change the code and only have one commit in my pull request.

Things I have tried:

I tried resetting the HEAD to initial commit by git reset HEAD~2 --soft and then git commit -a -m "combined commit message" but then when I am pushing this branch to my remote repository then a pop-up appears which says "This branch has conflicts with the remote branch which need to be resolved" with options merge and rebase. I know what that means. It's because I am changing the same code which is there in my remote branch. So I want to rebase. Then there is a received commit a. Then I again run git reset HEAD~2 --soft and again git commit -a -m "I have received the commit and I am combining these two commits again" but when I again push it, the same pop up appears.

Any help? How to change the same code and still have one commit in that pull request?

m_vemuri

After making your code changes, you can run a git commit --amend and then force push the changes to your fork/branch. The amend and force push will then take the changes but only show it as the same commit in your fork/branch.

Note: If using github, the changes will get picked up in the pull request (PR), but there will be a log stating that you force pushed in the PR (In my experience, maintainers of repo's that i've submitted PRs to have never really pointed it out or raised any concern about it).

git commit --amend

You don't need to make changes here. So just save it with the same message, unless you want to actually also change the commit message. Then force push:

git push -f

This will override the existing commit with your new changes (and new commit message if changed in the previous step)

Note: The standard and widely popular git force pushing PSA (public safety announcement) applies - use force push with care. But if you've tested your code and it works, you should be fine.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Mercurial : how to deal with rejected pull request?

来自分类Dev

How to squash squashed migration in django?

来自分类Dev

Apply Bitbucket pull request as a patch

来自分类Dev

Git workflow: submitting pull requests to upstream and using the commits in the meantime

来自分类Dev

git pull 和 git request-pull 的区别

来自分类Dev

获取对github pull request的最后推送的日期

来自分类Dev

如何从Git Pull Request中删除文件

来自分类Dev

github pull-request与合并问题

来自分类Dev

Devops Pull Request工作流程验证

来自分类Dev

获取对github pull request的最后推送日期

来自分类Dev

Github将pull_request的钩子发送到AmazonSNS

来自分类Dev

从本地分支到远程主站的git request-pull

来自分类Dev

如何在github上自动合并pull request?

来自分类Dev

如何使用GitHub API确定提交属于哪个Pull Request?

来自分类Dev

Git - work in new feature while some needed class are on pull request

来自分类Dev

如何在Jenkinsfile中设置github pull request构建?

来自分类Dev

在VSTS Pull Request中获取真实的源分支名称

来自分类Dev

如果JSLint失败,如何防止git pull request

来自分类Dev

What is the intended pull request rejection workflow in TFS/Team Services?

来自分类Dev

无法使用Jenkins GitHub Pull Request Builder更新GitHub PR

来自分类Dev

下游Jenkins GitHub Pull Request Builder的正确配置

来自分类Dev

如何通过API对Bitbucket Pull Request进行Markdown / HTML注释?

来自分类Dev

Android Studio View Pull Request功能已禁用

来自分类Dev

更新Pull Request Azure devOps的审阅者时获取异常

来自分类Dev

Github将pull_request的钩子发送到AmazonSNS

来自分类Dev

在VSTS Pull Request中获取真实的源分支名称

来自分类Dev

Jenkins和Github Enterprise 2.17仅失败的Pull Request构建

来自分类Dev

Github Pull Request API与网络工作流程不同

来自分类Dev

SonarQube github pull request 插件删除我的评论

Related 相关文章

  1. 1

    Mercurial : how to deal with rejected pull request?

  2. 2

    How to squash squashed migration in django?

  3. 3

    Apply Bitbucket pull request as a patch

  4. 4

    Git workflow: submitting pull requests to upstream and using the commits in the meantime

  5. 5

    git pull 和 git request-pull 的区别

  6. 6

    获取对github pull request的最后推送的日期

  7. 7

    如何从Git Pull Request中删除文件

  8. 8

    github pull-request与合并问题

  9. 9

    Devops Pull Request工作流程验证

  10. 10

    获取对github pull request的最后推送日期

  11. 11

    Github将pull_request的钩子发送到AmazonSNS

  12. 12

    从本地分支到远程主站的git request-pull

  13. 13

    如何在github上自动合并pull request?

  14. 14

    如何使用GitHub API确定提交属于哪个Pull Request?

  15. 15

    Git - work in new feature while some needed class are on pull request

  16. 16

    如何在Jenkinsfile中设置github pull request构建?

  17. 17

    在VSTS Pull Request中获取真实的源分支名称

  18. 18

    如果JSLint失败,如何防止git pull request

  19. 19

    What is the intended pull request rejection workflow in TFS/Team Services?

  20. 20

    无法使用Jenkins GitHub Pull Request Builder更新GitHub PR

  21. 21

    下游Jenkins GitHub Pull Request Builder的正确配置

  22. 22

    如何通过API对Bitbucket Pull Request进行Markdown / HTML注释?

  23. 23

    Android Studio View Pull Request功能已禁用

  24. 24

    更新Pull Request Azure devOps的审阅者时获取异常

  25. 25

    Github将pull_request的钩子发送到AmazonSNS

  26. 26

    在VSTS Pull Request中获取真实的源分支名称

  27. 27

    Jenkins和Github Enterprise 2.17仅失败的Pull Request构建

  28. 28

    Github Pull Request API与网络工作流程不同

  29. 29

    SonarQube github pull request 插件删除我的评论

热门标签

归档