0% found this document useful (0 votes)
40 views

A Short Introduction To Git

Git is a version control system that tracks changes to files over time, allowing users to revert files to previous versions, view file histories and differences between versions, and collaborate by merging multiple users' changes; it works by storing snapshots of file content and tracking each file's revision, commit, and change history in a special hidden .git directory in each repository folder. Key Git commands include commit, diff, log, status, and show to manage and inspect the revision history, and the staging area holds changes that have not been committed yet.

Uploaded by

Razo ana
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

A Short Introduction To Git

Git is a version control system that tracks changes to files over time, allowing users to revert files to previous versions, view file histories and differences between versions, and collaborate by merging multiple users' changes; it works by storing snapshots of file content and tracking each file's revision, commit, and change history in a special hidden .git directory in each repository folder. Key Git commands include commit, diff, log, status, and show to manage and inspect the revision history, and the staging area holds changes that have not been committed yet.

Uploaded by

Razo ana
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Git:

Version control system: Tool that manages changes made to files in a project. Git strengths are:

•Nothing that is saved to Git is ever lost, so you can always go back to see which results
were generated by which versions of your programs.

•Git automatically notifies you when your work conflicts with someone else's, so it's
harder (but not impossible) to accidentally overwrite work.

•Git can synchronize work done by different people on different machines, so it scales as
your team does.

Repository:
• Proyect files.
• Git records about project’s history. -> .git in proyect root

Console commands:
• “git“
◦ “ anotate “file”” - Shows who made the last change to each line of a file and when.
◦ “ commit” - Saves everything in the staging area as one unit.
▪ “ -m” - Log message - “Sample”
▪ By default, opens a text editor with a template.
• # this is a comment
◦ “ diff” - Formatted display of the differences between two sets of files.
▪ “ filename”. - File to show changes.
▪ “ -r” - Compare to a particular revision.
• “ HEAD” - shortcut meaning "the most recent commit".
◦ “~1” - commit before head – change “1” for “n” to keep going back.
▪ “ ID1. .ID2” - See the changes between two commits.
◦ “ log” - Displays proyect history of changes.
▪ “ path” - Inspect only the changes to particular file or path.
◦ “ show” - Displays the details of the commit with the specified hash.
▪ “ [Part of a hash]”
◦ “ status” - Dispays changes to be commited

Staging area in which it stores files with changes you


want to save that haven't been saved yet. Putting files
in the staging area is like putting things in a box,
while committing those changes is like putting that
box in the mail: you can add more things to the box or
take things out as often as you want, but once you
put it in the mail, you can't make further changes.
Diffs is displayed like this:
diff --git a/report.txt b/report.txt
index e713b17..4c0742a 100644
--- a/report.txt
+++ b/report.txt
@@ -1,4 +1,4 @@
-# Seasonal Dental Surgeries 2017-18
+# Seasonal Dental Surgeries (2017) 2017-18

TODO: write executive summary.


This shows:

•The command used to produce the output (in this case, diff --git). In it, a and b are
placeholders meaning "the first version" and "the second version".
•An index line showing keys into Git's internal database of changes. We will explore
these in the next chapter.
•--- a/report.txt and +++ b/report.txt, which indicate that lines being removed are
prefixed with -, while lines being added are prefixed with +.
•A line starting with @@ that tells where the changes are being made. Here, the line
shows that lines 1-4 are being removed and replaced with new lines.
•A line-by-line listing of the changes with - showing deletions and +showing additions.
(We have also configured Git to show deletions in red and additions in green.) Lines
that haven't changed are sometimes shown before and after the ones that have in
order to give context; when they appear, they don't have either + or - in front of them.

Desktop programming tools like RStudio can turn diffs like this into a more readable side-by-
side display of changes; you can also use standalone tools like DiffMerge or WinMerge.

How does Git store information?


In order to make common operations fast and
minimize storage space, Git uses a multi-level
structure to store data. In simplified form, this
has three key parts:
1. Every unique version of every file. (Git calls these blobs because they can contain data
of any kind.)
2. tree that tracks the names and locations of a set of files.
3. A commit that records the author, log message, and other properties of a particular
commit.

Hash
Every commit to a repository has a unique identifier called a hash (since it is generated by
running the changes through a pseudo-random number generator called a hash function). This
hash is normally written as a 40-character hexadecimal string. Git compares hashes, not entire
files.

Text editors:
• “nano”
◦ “ filename” - Opens or creates file for editing.
◦ ControlKeys:
▪ Ctrl-K: delete a line.

▪ Ctrl-U: un-delete a line.

▪ Ctrl-O: save the file ('O' stands for 'output').

▪ Ctrl-X: exit the editor.

You might also like