Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
In a DVCS, clients don’t just check out the latest snapshot of the files: they fully mirror the repository.
Every time you commit, Git takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored.
Most operations in Git only need local files and resources to operate.
For example, to browse the history of the project, Git doesn’t need to go out to the server to get the history and display it for you—it simply reads it directly from your local database.
Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it.
The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory. A SHA-1 hash looks something like this:
24b9da6552252987aa493b52f8696cd6d3b00373
Now we will get for basic command.
You can get a Git project using two main approaches. The first takes an existing project or directory and imports it into Git. The second clones an existing Git repository from another server.
$ git init
git clone [url]
$ git clone https://github.com/Cotard/git-presentation.git
$ git status
# On branch master nothing to commit (working directory clean)
Let’s say you add a new file to your project, a simple README file. If the file didn’t exist before, and you run git status, you see your untracked file like so:
$ vim README
$ git status
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# README
nothing added to commit but untracked files present (use "git add" to track)
$ git add README
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: README
#
Here is example .gitignore file:
# a comment - this is ignored
# no .a files
*.directory
# only ignore the root TODO file, not subdir/TODO
/TODO
$ git diff
diff --git a/benchmarks.rb b/benchmarks.rb
index 3cb747f..da65585 100644
--- a/benchmarks.rb
+++ b/benchmarks.rb
@@ -36,6 +36,10 @@ def main
@commit.parents[0].parents[0].parents[0]
end
+ run_code(x, 'commits 1') do
+ git.commits.size
+ end
+
run_code(x, 'commits 2') do
log = git.commits('master', 15)
log.size
Your staging area is set up the way you want it, you can commit your changes.
$ git commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Committer: user
#
# On branch gh-pages
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: index.html
#
To not to write message in editor, I use command:
$ git commit -a -m "commit message"