This article will help you to change the Git change after committing the code in to the repository
Two way you can amend the commit changes
- Change in the last commit
- Changes in the last 5 commits
1. Change in the last commit
This will help you to change in the last commit changes
If you changed the message of most recently pushed commit, you would have to force push it.
Syntax
git commit --amend -m "New message" git push --force
Example
git commit --amend -m "After finishing the Project Module" git push --force
Note
- Make sure that your fellow developer aware about this changes
- Properly use the Repository Name Branch Name
2. Amend in pushed commit last 5 commits
This will help you to make the changes in the last committed
git rebase -i HEAD~3 pick a5bf3ae After Adding Buttom pick f79eb62 Using State Hooks pick 4788f64 After Changing Button Color # Rebase 172e023..4788f64 onto 172e023 (3 commands) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
- It will prompt the last commits in the console
- You are going to edit this by using VIM Editor
- You can press the I button to insert or Edit the change
- You can change the pick to reword to make the change in commit
- Now you may press Escape and :wq to save and quite VIM editor
Now you can proceed to push the changes
git push –force
Note
- Make sure that your fellow developer aware about this changes
- Properly use the Repository Name Branch Name