Reputation: 1151
I am the sole developer on a project I am working on. I am using git and Github for version control.
My workflow is quite simple:
feature_branch
from master.feature_branch
is done, it is pushed upstream.The previous commit that was squash merged into master on remote was missing a one-line comment. I could always follow the protocol outlined above and create a new local branch, push it up and merge it into master with this change. However, it seems like such a waste just for a one-line comment.
One solution I thought of was to perform the following steps:
git checkout master
git reset HEAD~ // Revert last commit
// Add the missing comment to my code
git add .
git commit -m 'Commit message' // This would be the same commit message as the reverted commit
git push -f origin master
Questions:
Upvotes: 0
Views: 128
Reputation: 1236
A push -f
can mess up version history. If you know what you are doing, it won't. The commands you are doing won't mess up history, as long as you are not out-of-date on your local repo. (Make sure to do a git fetch origin
right before you git push -f
).
That being said, even if you are sure you won't be messing up history, you still may not want to do this. You are creating a new commit and replacing the existing commit (even if you are only adding a one line comment). If someone has updated with your original commit, you may cause them trouble by replacing your commit with a new one.
In the case where you are working with other people and have already pushed your commits, I strongly recommend not re-writing history--instead create a new commit after your original with any fixes you need.
Upvotes: 1