0

I know I could merge some commits into one by git commit --amend for the commits has not been pushed.

But what about the commits already being pushed?

Assume there are no other commits being pushed to remote recently. So I would like to merge the top commit in the remote and some recently changed files in the local branch. Thanks.

Bostonian
  • 615
  • 7
  • 16
  • 1
    Does this answer your question? [Git prevents pushing after amending a commit](https://stackoverflow.com/questions/18588974/git-prevents-pushing-after-amending-a-commit) – BitLord Nov 19 '19 at 04:39

3 Answers3

1

git-rebase is what your're looking for.

git rebase -i HEAD~n

LF00
  • 27,015
  • 29
  • 156
  • 295
0

You can follow below steps to first stash your changes, reset the local to remote, apply the stash(if there are merge conflicts resolve the same), add your changes and finally amend your commit and push the same.

Git stash

git stash #add the changes
git fetch origin
git reset --hard origin/master #resetting local to remote 
git stash apply #apply the stashed changes
git add . #stage the local changes
git commit --amend #amending the commit
git push #pushing the changes to remote
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
0

I agree with Kris, git rebase will get that done. You can look up the following documentation to properly understand more: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase and https://git-scm.com/book/en/v2/Git-Branching-Rebasing

PS: git rebase -i HEAD~n

where n = number of commits

Sylva Elendu
  • 341
  • 2
  • 9