Search code examples
gitgithubgit-branchgit-commit

Github commiting in the same commit that prevousely commited


I want to keep same commit with another change like.

Few hours ago, i commuted a change and push to my origin like.

git commit -m "header removed"

and later i push it to remote origin like:

git push origin mybranhname

After pushing i realized i need to change something again and i changing some code again.

Now i want to push the change in the same commit, is it possible?

I mean, i dont want to commit again with the new named commit. I want to commit with the header removed

I dont want to open new commit. can i do it?


Solution

  • If the branch is not shared (either you're working alone on the whole repo or alone on this branch), just amend and force-push :

    # do your changes in the file, then
    git add path/to/changed/file
    git commit --amend
    git push --force origin HEAD
    

    But you should not do this if the branch is shared. In that case, you'll have to keep the new changes as a new commit and push it on top of the branch as usual.