Introduction to Merge and Revert Operation
Posted By : Mohit Shakya | 09-Jan-2017
Previously we discussed about some special commands in git as 'Reset', 'Checkout' and 'Stash'.
In this blog, i'll let you know about some important commands and some scenarios occurs in day to day git life.
We'll include following points in this blog:
* Merge - merging between two branches
* Revert - revert a non-required or wrong commit
* Problem: how to do changes in an older commit
Merge - merging between two branches
When we have more than one branches with different codebase, we often require to collect one branch's data into another.
This is done by merge technique in git.
* To merge a branch namely 'A' to branch namely 'B', we use following procedure:
* clear the non-committable data (using stash or reset --hard) or commit and push the available data to remote of current branch
* checkout to branch that to be merge
$ git checkout origin A
* get the latest codebase of mergeable branch
$ git pull origin A (get latest codebase of that branch)
* switch to the branch where to merge
$ git checkout origin B
* get latest codebase of this branch
$ git pull origin B
* use merge command to merge the branch A into B
$ git merge origin/A
* resolve the conflicts (find my another blog on how to handle conflicts)
* push to the remote git repository
$ git push origin B
Revert - revert a non-required or wrong commit
Often we do a wrong commit in repository, to revert such commits from repository use following git command under your git repository:
$ git revert <commit_hash>
( NOTE: this revert may cause some serious conflict if commit is older )
to update remote repository with current reverted commit, simply:
$ git push origin <current_branch_name>
Problem: how to do changes in an older commit
Sometimes, we require to do some changes in an older commit, to do so we have follow this procedure:
* go back to that specific commit
$ git checkout <commit_hash>
* do your changes and commit them
* now get aligned with latest codebase
$ git pull origin <current_branch_name>
Thanks for reading my blog, your comments will be valuable.
Mohit has worked in groovy and grails, filesystems, ffmpeg. Mohit likes to be adventurous, likes music, solving puzzles, playing chess, and basketball.