Detaching HEAD:
Detaching HEAD just means attaching it to a commit instead of a branch. This is what it looks like beforehand:
Start:
git checkout C1 ->
- git checkout master
- git commit
- git checkout C2
- Examples:
2.Purpose branch:Type command:- git checkout C4.
Moving around in Git by specifying commit hashes can get a bit tedious. In the real world you won't have a nice commit tree visualization next to your terminal, so you'll have to usegit logto see hashes.
Furthermore, hashes are usually a lot longer in the real Git world as well. For instance, the hash of the commit that introduced the previous level isfed2da64c0efc5293610bdd892f82a58e8cbc5d8. Doesn't exactly roll off the tongue...
The upside is that Git is smart about hashes. It only requires you to specify enough characters of the hash until it uniquely identifies the commit. So I can typefed2instead of the long string above.
Monday, October 29, 2018
Lesson5: Detaching Head in git
Friday, October 26, 2018
Lesson 4.1: Can I recover a branch after its deletion in Git?
- How to recover branch if you deleted it:
git branch -d XYZ, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command?Resolve:
Instruction recover step by step:
git refloggit checkout [sha]git checkout -b [branchname]
Wednesday, October 17, 2018
Lesson3: Git merge
Now we need to learn some kind of way of combining the work from two different branches together. This will allow us to branch off, develop a new feature, and then combine it back in.
Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means "I want to include all the work from this parent over here and this one over here, and the set of all their parents.".
Git command line:
Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means "I want to include all the work from this parent over here and this one over here, and the set of all their parents.".
- Let's merge
masterintobugFix:
git checkout bugFix; git merge master
SincebugFixwas an ancestor ofmaster, git didn't have to do any work; it simply just movedbugFixto the same commitmasterwas attached to.
- Make a new branch called
bugFix - Checkout the
bugFixbranch withgit checkout bugFix - Commit once
- Go back to
masterwithgit checkout - Commit another time
- Merge the branch
bugFixintomasterwithgit merge
Goal:
: - Make a new branch called
Git command line:
$ git checkout -b bugFix
$ git commit
$ git checkout master
$ git commit
$ git merge bugFix
Subscribe to:
Comments (Atom)