git gui branch management

牧云@^-^@ 提交于 2019-12-12 21:26:46

问题


Hi I am an inexperienced Git user on Windows. I am using Git Gui. I am interested in Branch Management.

My repo has a branch called 'leafy', how do I check this branch out to my local machine, and them cherry pick a commit from master into leafy?

Thanks a LOT

--MB


回答1:


Thanks for replies, but I said I am using Git Gui

To checkout newly created branch (exists on server, not locally), it's a 2 step process:

  1. Git Gui -> Branch -> Check Out -> Tracking Branch -> Choose Branch

  2. Branch -> Create -> Name = same name as tracking branch you chose -> Choose This Detached Checkout

You are now using the branch.

Another useful and obvious thing -> to switch to another branch -> Branch -> Check Out -> Local Branch .....




回答2:


how do I check this branch out to my local machine

Everything is already on your local machine, what checkout does is to update the files in your file system to match the state of the commit you are checking out.

git checkout leafy

updates your files with the content of the commit at the top of the branch (note that if you have uncommited changes in your files, git refuses to checkout. This is done to prevent you from losing changes. You can override this behaviour by adding the -f option). It also sets leafy as your current HEAD, in this case your current HEAD defines which branch you are on.

Then to cherry-pick, you need to find out the SHA1 ID of the commits you want to pick (gitk --all& might be handy here). Then use several git cherry-pick <the-interesting-SHA1-ID> in the correct order to cherry-pick the commits.




回答3:


To switch to the "leafy" branch:

git checkout leafy

To cherry-pick a commit, given its SHA1 identifier:

git cherry-pick abc123



回答4:


Other answers didn't work for me.
Wasted an hour on this.

Below sequence worked:

First time/ new remote branch:

Get newly created remote repositories list:

Branch -> Checkout
Revision > Tracking Branch >  {select your origin/remote-branch} > Checkout

Switch to your branch:

Branch -> Create
Branch Name > Match Tracking Branch Name
Starting Revision > Tracking Branch >  {select your origin/remote-branch} > Create

Later, once checked out, simply do:

Branch -> Checkout
Revision > Local Branch >  {select your local-branch} > Checkout

Hope that helps.



来源:https://stackoverflow.com/questions/4730760/git-gui-branch-management

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!