Version Control with git

Sys-Admin page

What is version control?

A version control system is a tool that manages changes made to the files and directories in a project. Many version control systems exist; this webpage focuses on one called Git, which is the most popular version control system these days. Its 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.

Version control isn't just for software: books, papers, parameter sets, and anything that changes over time or needs to be shared can and should be stored and shared using something like Git.

Where does Git store information?

Each of your Git projects has two parts: the files and directories that you create and edit directly, and the extra information that Git records about the project's history. The combination of these two things is called a repository.

Git stores all of its extra information in a directory called .git located in the root directory of the repository. Git expects this information to be laid out in a very precise way, so you should never edit or delete anything in .git.

What is a 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 like 7c35a3ce607a14953f070f0f83b5d74c2296ef93, but most of the time, you only have to give Git the first 6 or 8 characters in order to identify the commit you mean.

Hashes are what enable Git to share data efficiently between repositories. If two files are the same, their hashes are guaranteed to be the same. Similarly, if two commits contain the same files and have the same ancestors, their hashes will be the same as well. Git can therefore tell what information needs to be saved where by comparing hashes rather than comparing entire files.

How can I view a specific commit?

To view the details of a specific commit, you use the command git show with the first few characters of the commit's hash. For example, the command git show b37ee1679e44e8 produces this:


commit b37ee1679e44e8efc0b8cb6213fe017dc50284f0 (origin/master, origin/HEAD)
Author: Odai Alali <alali@informationsgesellschaft.com>
Date:   Mon Aug 12 10:02:23 2019 +0200

    fix(Project Information Widget): add website link settings

diff --git a/src/components/widgets/ProjectInformationWidget.vue b/src/components/widgets/ProjectInformationWidget.vue
index 5a59754..76c25d9 100644
--- a/src/components/widgets/ProjectInformationWidget.vue
+++ b/src/components/widgets/ProjectInformationWidget.vue
@@ -1,5 +1,5 @@
 <template>
-    <base-widget ref="baseWidget" :widget="widget" :editMode="editMode" :extraSettingsProps="['projectName', 'projectDescription', 'projectImage', 'projectContact', 'imageWidth', 'imageAlignment', 'imageTextStack']">
+    <base-widget ref="baseWidget" :widget="widget" :editMode="editMode" :extraSettingsProps="['projectName', 'projectDescription', 'projectImage', 'projectContact', 'imageWidth', 'imageAlignment', 'imageTextStack', 'websiteLink']">
         <v-layout :row="widget.extraSettings.imageTextStack === 'row'" :column="widget.extraSettings.imageTextStack === 'column'">
             <v-flex xs6 :style="{ 'text-align': widget.extraSettings.imageAlignment || 'center' }">
                 <v-img
@@ -11,6 +11,7 @@
                 <div class="headline" v-if="widget.extraSettings.projectName">
                     {{widget.extraSettings.projectName}}
                 </div>
+                <a target="_blank" v-if="widget.extraSettings.websiteLink" :href="widget.extraSettings.websiteLink">{{widget.extraSettings.websiteLink}}</a>
                 <div class="body-2" v-if="widget.extraSettings.projectDescription" style="white-space: pre-wrap;">{{widget.extraSettings.projectDescription}}</div>
                 <div class="body-2" v-if="widget.extraSettings.projectContact" style="white-space: pre-wrap;">{{widget.extraSettings.projectContact}}</div>
             </v-flex>
@@ -31,6 +32,7 @@
             <v-layout wrap>
                 <v-flex xs12 md6>
                     <v-text-field label="Project Name" v-model="extraSettingsFormModel.projectName"></v-text-field>
+                    <v-text-field label="Project Website Link" v-model="extraSettingsFormModel.websiteLink"></v-text-field>
                     <v-textarea label="Project Description" v-model="extraSettingsFormModel.projectDescription" auto-grow @keyup.native.enter.stop></v-textarea>
                     <v-textarea label="Project Contacts" v-model="extraSettingsFormModel.projectContact" auto-grow @keyup.native.enter.stop></v-textarea>
                 </v-flex>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

The first part is the same as the log entry shown by git log. The second part shows the changes; as with git diff, lines that the change removed are prefixed with -, while lines that it added are prefixed with +.

Reference

Introtext inspired by Introduction to Git for Data Science (opens new window)

Sys-Admin

Sys-Admin page