As writing tradition entails, I have to Introduce Git and explain what it generally means but this is beyond just git, this article is more about git, as I believe you already have ground knowledge about git and you are looking to get in-depths this article is centered around "Git Revert", "Git Rebase" and "Git cherry-pick".
We start off with the git revert:
The two commands needed to perform a revert are the git log/git reflog and git revert
$ git log
$ git reflog
The git reflog command is used to record updates made to the tip of branches. It allows to return to commits even to the ones that are not referenced by any branch or any tag also the git log while git log shows commits in descending order based on commit datetime.
This two commands were mentioned first because it is needed to perform a git revert command. The git revert would most likely be used when you realize that there was a bug in your last commit and you need to rectify to continue working on new tasks.
The git revert command will undo changes in a project commit history without tampering with it. This is why you have to run the git log
or git reflog
command to target the specific commit you might want to revert to.
git revert <commit hash>
Git Rebase
The Git rebase command literally combines two source code branches into one. This command takes all of the commits from the branch you’re going to rebase(eg dev-branch) and replays them onto the end of the branch you’re rebasing(eg main branch) to and after it is successful, the dev-branch will be removed.
Steps to take while you want to Git Rebase
First, confirm that the head branch has no outstanding changes.
git status
You checkout the new-feature branch.
git checkout new-feature
We tell Git to rebase the current branch onto the main branch.
git rebase main
We swap back to the main branch
git checkout main
We merge the new-feature branch into the current branch, which in our case is the main branch.
git merge new-feature
Git Cherry-pick
Generally, the git cherry-pick command enables you to copy a commit from anywhere in your repository and append it to the HEAD of the current branch.
One downside to using this command is that it creates duplicate commits which creates a foggy git history. To use git cherry-pick you need to find the commit reference you are interested in and the use git cherry-pick <commit_reference>
after you have checked out the branch you want to bring in the particular functionality referenced in the 'commit_reference' into.
Top comments (0)