It was my first full fledged feature and I was excited to know review comments from my manager. As much as the excitement, the learning that came with taking action on each comment was tremendous and I still can't describe how good I feel about it.
It's one of the times when I thought Git to be, "Wow! what an invention!!"
Although I had some code refactors, most of the comments were to split my single commit into several different commits for the sake of CI picking them up.
I thought, it's simple. I can amend my previous commit to remove files from existing commit and make them part of new commits. That's where trouble came up. I cannot remove a dependency and try to use it assuming I will have that as part of an upcoming commit.
I definitely will have to go back in time to push a commit. At first I thought, I'll change my latest commit to be a dependency commit and create new commit for feature. However that involved a lot of manual work which would defeat the purpose of git itself in the first place. I had to come up with some different trick and as usual I went in search. My search phrases went as,
- create commits in between
- push a commit before latest commit
- alter commit history to add commit
* Please read this post fully before executing any command. My scenario might not be same as yours.
So the steps involved are as follows,
- Execute git log
- Copy the commit hash after which you have to push a new commit
- Do a git checkout <copied_commit_hash>. For instance, git checkout 54ace3456ka235rtyc90
- After that, your head is pointing to the mentioned commit hash.
- Now, make any change and do the required commit(s)
- Once you are done with all your commits, you will have to rebase with the below mentioned command,
git rebase --onto HEAD <copied_commit_hash> <your_working_branch>
git rebase --onto HEAD 54ace3456ka235rtyc90 working/my-new-feat
- Now, all the commits you made after the checkout will be showing past your top most commit. You could verify that by executing git log.
Git is like Time travel, whatever you want you can achieve. Thanks for sharing this blog..ReplyDelete