If you have multiple branches in your repository and there are set of commits applied at one branch
, e.g., Branch1
- changes for web.config (commit no: ediekd3839929293)
- changes for db (commit no: gdjsk29182kdlk)
Now you want to merge code change for db (gdjsk29182kdlk) in Branch2.
Then first goto Branch2
- git checkout Branch2
Merge changes from commit no/hash that you want , e.g.,
- git cherry-pick gdjsk29182kdlk
# Create new branch like exisiting one
git checkout -b <branch name>
# To create empty branch
git branch --orphan <branchname>
# Undo unstaged changes
git reset --hard
Note: be cautious this it'll reset unstaged changes in the repository, so use this when you're really sure
# There are some cool features that you can leverage at Unix/Linux terminal by concatenating multiple commands
&& Combine two commands to execute in single line , e.g.,
- git reset --hard && git checkout -b newbranch1
GIT is fantastic tool, incase you've any query then reach out to me @sumitjolly (twitter)It'll first reset all unstaged changes and then create newbranch1 like current branch
Guest UserPosted Jul 10, 2014, 9:30 AM
Sure Mahesh! I'll write down article on basics of GIT. I made assumption that most people are aware of it. Thanks for feedback!
Mahesh ChandPosted Jul 10, 2014, 8:17 AM
Sumit, good start on Git. I think it will be nice to write an introduction article on Git. What is Git all about. Why it should be used and how to use it. Experienced developers know it but many people don't know about it. Cheers!
Guest UserPosted Jul 10, 2014, 5:25 AM
Guys, what I really appreciate is your valuable feedback? Tell me what did you like, anything you would like to see in this blog? Your precious feedback can help me improve. THANKS to All!