If I have N
commits, how do I branch from the N-3
commit?
You can create the branch via a hash:
git branch branchname <sha1-of-commit>
To do this on github.com:
The magic can be done by git reset<\/strong> .
"
If you are not sure which commit you want to branch from in advance you can check commits out and examine their code (see source, compile, test) by
git checkout <sha1-of-commit>
Simply run :
git checkout -b branch-name <commit>
For example :
git checkout -b import/january-2019 1d0fa4fa9ea961182114b63976482e634a8067b8
The checkout
command with the parameter -b
will create a new branch AND it will switch you over to it
git checkout -b <branch-name> <sha1-of-commit>
This creates the branch with one command:
git push origin <sha1-of-commit>:refs/heads/<branch-name>
A great related question is: How the heck do you figure this out using the --help<\/code> option of git?
Let's try this:
git branch --help
Using Sourcetree | The easiest way.
This is what I did:
C:\Users\[path]\build>git checkout -b responsivenavigation 8a75b001096536b3216022484af3026aa9c7bb5b
Switched to a new branch 'responsivenavigation'
C:\Users\jaimemontoya\[path]\app>git branch
master
* responsivenavigation
To do this in Eclipse:
It will create a local branch for you. Then whenever you push your changes, your branch will be pushed to the remote server.
"I was able to do it like so:
git branch new_branch_name `git log -n 1 --skip 3 --format=%H`
You can do it in Stash.
Go to a particular commit of a git repository<\/em><\/strong>
To do that all you need it the SHA-1 hash of the commit which you can easily find checking the log with the command:
git log --abbrev-commit --pretty=oneline
To do the accepted answer in Visual Studio 2015 & 2017:
Click in alterations (red arrow above)
Click in Actions (red arrow above) and click in View History on the DropDown Menu
And new Tab will open:
And you should right click the previous commit that you want your code to revert to:
Choose to checkout a new branch and voilá!
Below, although not part of OP question, but I do both a lot and this one is a trick step, at least to me: if you want to revert to a previous commit, without checkout a new branch, DO NOT choose revert(!?); you should choose redefine --mixed or --hard:
If you are looking for a command-line based solution, you can ignore my answer. I am gonna suggest you to use GitKraken<\/a> . It's an extraordinary git UI client. It shows the Git tree on the homepage. You can just look at them and know what is going on with the project. Just select a specific commit, right-click on it and select the option 'Create a branch here'. It will give you a text box to enter the branch name. Enter branch name, select 'OK' and you are set. It's really very easy to use.
"I used Git Gui (which comes with GIT for Windows).
With GitHub Desktop, display the history pane and right click on the commit you want, then choose the menu item "Create branch from commit".
Branch...
option.Create branch
.if you use source tree that is pretty straight forward.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.