Reputation: 4099
I have not used Git extensively and so I usually end up searching for my answers to my Git questions online without much trouble. However yesterday I encountered a problem I haven't faced before and wasn't sure the correct Git way to go about it when searching online. Here's the problem I faced:
Here in lies my problem, I need to grab my commit, make some changes and then re-commit them. My question is this, what is the proper way to grab my commit changes that were reverted, edit them and then re-commit them?
What I did: I solved my issue by pulling from master to get up to date, then went to the Bitbucket server and selected my commit, downloaded the files and copied those files back into the project. Then I proceeded to make changes. This allowed me to do git status and see those files were changed and also use git difftool to compare my changes with master before committing to ensure I want the changes I am committing.
I tried checking out the commit but then the files didn't end up showing up as modified and wasn't sure where to go from there... Was I supposed to branch from the commit, make changes on that branch and then merge it back into master?
Upvotes: 2
Views: 117
Reputation: 1077
If your changes were removed from master you might need to check the reflog to find them.
https://git-scm.com/docs/git-reflog
Once you find your changes you can check them out, create a branch and merge them back into master.
Upvotes: 0
Reputation: 312219
The master currently contains your changes and a commit that reverts them. While the current master doesn't contain your changes, the important thing is to remember that these commit aren't gone. The easiest thing would be to cherry-pick your original commit to the branch you're working on, complete the work and then git commit --amend
your additional changes to create a commit with the full change.
Upvotes: 2