GitHub pull request showing commits that are already in target branch

前端 未结 11 1047
孤城傲影
孤城傲影 2020-12-12 09:29

I\'m trying to review a pull request on GitHub to a branch that isn\'t master. The target branch was behind master and the pull request showed commits from master, so I merg

相关标签:
11条回答
  • 2020-12-12 10:19

    You need to add the following to your ~/.gitconfig file:

    [rebase]
        autosquash = true
    

    This will automatically achieve the same as what this answer shows.

    I got this from here.

    0 讨论(0)
  • 2020-12-12 10:20

    I'm not exactly sure about the theory behind this. But I got this several times and able to fix this by doing the following.

    git pull --rebase
    

    This will fetch and merge the changes from your original repo master branch (If you have point to that)

    Then you push your changes forcefully to your github cloned repository (target)

    git push -f origin master
    

    This will make sure your github clone and the your parent repo are at the same github commit level and you don't see any unnecessary changes across branches.

    0 讨论(0)
  • 2020-12-12 10:20

    I found a way to get the right behavior (tested in November 2020).

    After git merge and resolving conflicts need to use git merge --continue instead of git commit ....

    0 讨论(0)
  • 2020-12-12 10:24

    Fail safe approach if you are too worried about messing things up: go to the file and manually remove the changes, then squash with your last commit using

    git add .  && git commit -a --allow-empty-message -m '' && git reset --soft HEAD~2 &&
    git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
    

    I there are no conflicts, you are good to go!

    0 讨论(0)
  • 2020-12-12 10:25

    One way to fix this is to git rebase targetbranch in that PR. Then git push --force targetbranch, then Github will show the right commits and diff. Be careful with this if you don't know what you are doing. Maybe checkout a test branch first to do the rebase then git diff targetbranch to make sure it is still what you want.

    0 讨论(0)
提交回复
热议问题