I do manage git in an organized way, as per my knowledge. I commit every specific changes, so that I can get back to a single bit of feature whenever I want. In this process, I've added a feature (commit #74fd458
) about 10 days ago, where I added a binary file and made changes in 3 tracked files.
After that I made at least 15 commits.
dfs4334
- new commit 152yu44m6
- new commit 14
...47jc063
- new commit 174fd458
- Target Commit (seems unwanted now)560dfsf
- old commit 1lfg956d
- old commit 2
...
Now I came to a situation that, that specific commit (read 'feature') is unnecessary. So, thing is very simple, open a commit visualizer and remove those specific lines made in that specific commit, remove that binary file that's added then, and you are done. But, you know it's messy.
Q: Is there any way I can keep all the changes I made afterward, but remove, or revert, or pick a specific commit out of the branch?
PS. As scenario can change anytime, that specific feature can be added later. So I don't want to remove that feature completely from version control, I just put those things out, but to keep them somewhere so that I can merge them anytime, if necessary.
Removing the last commit If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.
The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.
Do a fetch in your local repository to remove the reference to the removed branch. Create a new branch for the new commits. Reset the original branch to the last commit that was approved in the Pull Request. Push the original branch back to Bitbucket.
Is there any way I can keep all the changes I made afterward, but remove, or revert, or pick a specific commit out of the branch?
git revert
is probably what you are looking for.
From the documentation:
Revert some existing commits
Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them
In your case, both the original commit and the (let me say) revert commit will be part of the project's history.
You can revert the revert commit later if you need it, that is if you need to apply the original commit once more.
See the linked documentation for further details.
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