Git - Revision Control Perfected
Branching and Merging
The work you do in Git is specific to the current branch. A branch is simply a moving reference to a commit (SHA1 object name). Every time you create a new commit, the reference is updated to point to it—this is how Git knows where to find the most recent commit, which is also known as the tip, or head, of the branch.
By default, there is only one branch ("master"), but you can have as many
as you want. You create branches with git branch and switch between
them with git checkout. This may seem odd at first, but the reason
it's called "checkout" is that you are "checking
out" the head of that
branch into your working copy. This alters the files in your working
copy to match the commit at the head of the branch.
Branches are super-fast and easy, and they're a great way to try out new ideas, even for trivial things. If you are used to other systems like CVS/SVN, you might have negative thoughts associated with branches—forget all that. Branching and merging are free in Git and can be used without a second thought.
Run the following commands to create and switch to a new local branch named "myidea":
git branch myidea
git checkout myidea
All commits now will be tracked in the new branch until you switch to
another. You can work on more than one branch at a time by switching
back and forth between them with git checkout.
Branches are really useful only because they can be merged back together later. If you decide that you like the changes in myidea, you can merge them back into master:
git checkout master
git merge myidea
Unless there are conflicts, this operation will merge all the changes from myidea into your working copy and automatically commit the result to master in one fell swoop. The new commit will have the previous commits from both myidea and master listed as parents.
However, if there are conflicts—places where the same part of a file
was changed differently in each branch—Git will warn you and update
the affected files with "conflict markers" and not commit
the merge automatically. When this happens, it's up to you to edit the files by hand,
make decisions between the versions from each branch, and then remove the
conflict markers. To complete the merge, use git add on each formerly
conflicted file, and then git commit.
After you merge from a branch, you don't need it anymore and can delete it:
git branch -d myidea
If you decide you want to throw myidea away without merging it, use
an uppercase -D instead of a lowercase
-d as listed above. As a safety
feature, the lowercase switch won't let you delete a branch that hasn't
been merged.
To list all local branches, simply run:
git branch
Viewing Changes
Git provides a number of tools to examine the history and differences
between commits and branches. Use git log to view commit histories and
git diff to view the differences between specific commits.
These are text-based tools, but graphical tools also are available, such as
the gitk repository browser, which essentially is a GUI version of
git log --graph to visualize branch history. See Figure 2 for a screenshot.
Figure 2. gitk
Remote Repositories
Git can merge from a branch in a remote repository simply by transferring needed objects and then running a local merge. Thanks to the content-addressed storage design, Git knows which objects to transfer based on which object names in the new commit are missing from the local repository.
The git pull command performs both the transfer step
(the "fetch") and
the merge step together. It accepts the URL of the remote repository (the
"Git URL") and a branch name (or a full "refspec") as arguments. The
Git URL can be a local filesystem path, or an SSH, HTTP, rsync or
Git-specific URL. For instance, this would perform a pull using SSH:
git pull user@host:/some/repo/path master
Git provides some useful mechanisms for setting up relationships with remote repositories and their branches so you don't have to type them out each time. A saved URL of a remote repository is called a "remote", which can be configured along with "tracking branches" to map the remote branches into the local repository.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Home, My Backup Data Center
- Tech Tip: Really Simple HTTP Server with Python
- Please correct the URL for Salt Stack's web site
1 hour 6 min ago - Android is Linux -- why no better inter-operation
3 hours 22 min ago - Connecting Android device to desktop Linux via USB
3 hours 50 min ago - Find new cell phone and tablet pc
4 hours 48 min ago - Epistle
6 hours 17 min ago - Automatically updating Guest Additions
7 hours 26 min ago - I like your topic on android
8 hours 12 min ago - Reply to comment | Linux Journal
8 hours 33 min ago - This is the easiest tutorial
14 hours 48 min ago - Ahh, the Koolaid.
20 hours 26 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Interesting
Good to read this informative article here on this website. It’s an interesting post.
Thank you! wintersport oostenrijk chalet / wintersport oostenrijk chalet
Ich selber habe einige
Ich selber habe einige Webseiten und brauchte genau das, was ich hier lesen konnte. Könnte ja mal schauen, ob ich es richtig gemacht habe.
Liebe Grüße
http://www.flirtcenter24.de/
About Git
Worth keeping
Checking Out A Small Subset Of Files On A Small Device?
The limitation that I immediately ran into when I considered migrating to git is to check out some (rather randomly selected) subset of files on a small/portable computing device.
Say I have a big repository of files and I only needed a very small subset of files while on the go -- to refer to and to be edited.
It was originally a small netbook computer where I could check out a few directories from a big repository and be able to edit files on the netbook computer while on the bus.
Netbook might have grown larger with regard to its disk storage, but now, I want to do the same on an Android phone.
git's sparse checkout feature still pulls the entire repository to the device. It only checkout a subset of files to give the appearance of sparse checkout, but it doesn't resolve the storage issue.
I don't think git submodules help, as, I think, one can't easily move selected files across repositories with all history intact (i.e., every now and then, add some additional directories to the list available to small devices by moving them to a submodule, when it becomes necessary), as one can easily do with CVS.
The only solution that I can think of is to remotely mount .git/objects/ directory and deal with its limitation.
Is there any creative brain power would find a solution lift this limitation?
Thanks.
Split-able git Tree?
Given that:
Tree object = Blobs file names + permissions + Blobs collection.
Can splitting git repository be implemented by splitting some git's Tree object into 2 (sub-) Tree objects on a personal workstation, (perhaps new Commit objects to keep track of the split,) allowing a smaller tree be checked out to a small device.
Remote changes (done by others) can, then, be merged to the personal workstation (as staging), before merging to the splitted Tree branches for the small devices if necessary.
Changes on the small devices can be merged to the personal workstation (as staging), before being pulled by others?
Would that solve the disk space problem by limiting checkout to a small (sub-) Tree?
If this idea works, would some able developer turns it into an implementation?
Thanks.
On the guarantees of SHA1
First of all I want to thank the author for this clear and concise article.
However, I want to point out some inaccuracy regarding the paragraph on SHA1. The author states that SHA1 guarantees that the data in the blobs is different, and that the chance that two pieces of data have the same SHA1 is infinitesimally small. I disagree on this point.
The 40-character string that SHA1 outputs gives us 16^40 = 2^160 ~~ 10^16 different checksums. Although this is big enough to assume the above descripted 'guarantee', the claim about the infinitesimal chance is just wrong.
Consider for example 2^160 + 1 pairwise distinct files (this is data, be it hypothetical). The chance that there will be two different pieces of data in this set having the same checksum is 1. And 1 is very very different from infinitesimal.
I agree that it is highly unlikely that two such files will occur in practice, let alone in one project. (For example, each person on earth would have to create about 100.000 distinct files, to come close to the 2^160 files.) Still I wanted to point this out about the cryptographic features of SHA1.
There is not enough matter in
There is not enough matter in the universe to store 2^64 bits, much less 2^160 bits, even if you stored 1 bit per atom.
Your math is *way* off. 2^160
Your math is *way* off. 2^160 ~~ 10^48.
Very nice introduction
Congrats for a very clear and concise introduction for something as difficult to teach as git.
I love git, and had to give git training to Subversion users -- hard work! It really amounts to unlearning SVN and learn something completely new.