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
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.
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.
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 ...
.
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!
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.