I basically want to do:
git checkout branchA
git checkout -b branchB <commit_id>
which creates the new branchB branch from <commit_id> on branchA.
Question:
I'm getting into details here but the reason I'm asking is to help understand how git history works and to save a bit of typing. (the command above could of been four commands instead of two...) How do I get it to one with native git functions? Question:
Is there an easier/one line way of doing the same as above?
I was thinking of simply doing git checkout -b branchB <commit_id> but if I'm in branchC that probably won't work cause the log/history of branchC might not be the same as branchA.
Background:
My intension for this specific situation would be to quickly revert to a previous commit in case a bug was introduced to production. I however still want to keep my new code and then discard of the new branch one the old code was pushed back to the server.
Just
git checkout -b branchB <commit>
The hash of the commit is unique within the whole repository, thus there is no reason to change to branchA before, because the result is completely the same.
Also this is just a shortcut for
git checkout <commit>
git branch branchB
git checkout branchB
As you can see the first command is a normal checkout, that will supersede your git checkout branchA anyway.
I was thinking of simply doing
git checkout -b branchB <commit_id>but if I'm in branchC that probably won't work cause the log/history of branchC might not be the same as branchA.
There is only one history in one repository.
My intension for this specific situation would be to quickly revert to a previous commit in case a bug was introduced to production. I however still want to keep my new code and then discard of the new branch one the old code was pushed back to the server.
Sounds like tags ;)
git tag -a -m "Release 1.2.3" v1.2.3
# Deploy 1.2.3
#something broken!
git checkout v1.2.2
# Deploy 1.2.2
These commands
git checkout -b branchB <commit_id>
git checkout -b branchB branchA
mean I want to create a branch X based on branch (or commit) Y, thus you don't have to be in Y so that works.
The case were you would need to move to the base branch first is:
git checkout branchA
git checkout -b branchB
See that I didn't mention the base branch in the second line.
Also, remember that a commit is not specific to a branch, which is simply a pointer and nothing more. A branch can be deleted, move, renamed, etc. But the commits won't change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With