I have already push some commits on my git server on EC2 , not on github.
How can I modify those commits on the git server?
Operation like remove commit, like rebasing, change commit message
Is it possible?
Thanks so much.
Changing the Last Commit: git commit --amend. The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit.
To change the most recent commit message, use the git commit --amend command. To change older or multiple commit messages, use git rebase -i HEAD~N . Don't amend pushed commits as it may potentially cause a lot of problems to your colleagues.
You can do just about everything with a forced push. Change your local tree to exactly what you want and git push -f
and it will replace the tree on the server with what you have locally. It's worth noting that this will cause trouble with any other repos that have pulled the tree you just replaced.
If you want to edit a remote branch's history destructively (e.g. rebase
/amend
), make your changes locally and then do git push --force
. Sometimes it does not work (repository administrators can disable this feature); in that case, you can try deleting the remote branch with git push origin :my_branch
and then pushing it again with git push origin my_branch
. Otherwise you can use git revert
, which is the recommended way if you work in a team (the rule of thumb is that published history should not be modified).
Here's an example (using this Github repository):
$ touch SOMETHING
$ emacs SOMETHING
$ git add SOMETHING
$ git ci -m SOMETHING
[master d14aaa0] SOMETHING
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 SOMETHING
$ git push
Counting objects: 8, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 611 bytes, done.
Total 6 (delta 3), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
53f836a..d14aaa0 master -> master
$ git reset --hard "HEAD~"
HEAD is now at 7b2dc96 TODO update.
$ git push --force
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:23Skidoo/ghc-parmake.git
+ d14aaa0...7b2dc96 master -> master (forced update)
Looking at the commit history, you can see that commit d14aaa0 is absent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With