You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book-en/01-introduction/sections/about-version-control.asc
+14-15Lines changed: 14 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
=== About Version Control
2
2
3
3
(((version control)))
4
-
What is "version control", and why should you care?
4
+
What is "`version control`", and why should you care?
5
5
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.
6
-
For the examples in this book you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.
6
+
For the examples in this book, you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.
7
7
8
8
If you are a graphic or web designer and want to keep every version of an image or layout (which you would most certainly want to), a Version Control System (VCS) is a very wise thing to use.
9
-
It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
9
+
It allows you to revert selected files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
10
10
Using a VCS also generally means that if you screw things up or lose files, you can easily recover.
11
11
In addition, you get all this for very little overhead.
12
12
@@ -19,43 +19,42 @@ It is easy to forget which directory you're in and accidentally write to the wro
19
19
20
20
To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control.
21
21
22
-
.Local version control.
22
+
.Local version control
23
23
image::images/local.png[Local version control diagram]
24
24
25
-
One of the more popular VCS tools was a system called RCS, which is still distributed with many computers today.
26
-
Even the popular Mac OS X operating system includes the `rcs` command when you install the Developer Tools.
27
-
RCS works by keeping patch sets (that is, the differences between files) in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches.
25
+
One of the most popular VCS tools was a system called RCS, which is still distributed with many computers today.
26
+
https://www.gnu.org/software/rcs/[RCS] works by keeping patch sets (that is, the differences between files) in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches.
28
27
29
28
==== Centralized Version Control Systems
30
29
31
30
(((version control,centralized)))
32
31
The next major issue that people encounter is that they need to collaborate with developers on other systems.
33
32
To deal with this problem, Centralized Version Control Systems (CVCSs) were developed.
34
-
These systems, such as CVS, Subversion, and Perforce, have a single server that contains all the versioned files, and a number of clients that check out files from that central place. (((CVS)))(((Subversion)))(((Perforce)))
33
+
These systems (such as CVS, Subversion, and Perforce) have a single server that contains all the versioned files, and a number of clients that check out files from that central place. (((CVS)))(((Subversion)))(((Perforce)))
35
34
For many years, this has been the standard for version control.
36
35
37
-
.Centralized version control.
36
+
.Centralized version control
38
37
image::images/centralized.png[Centralized version control diagram]
39
38
40
39
This setup offers many advantages, especially over local VCSs.
41
40
For example, everyone knows to a certain degree what everyone else on the project is doing.
42
-
Administrators have fine-grained control over who can do what; and it's far easier to administer a CVCS than it is to deal with local databases on every client.
41
+
Administrators have fine-grained control over who can do what, and it's far easier to administer a CVCS than it is to deal with local databases on every client.
43
42
44
43
However, this setup also has some serious downsides.
45
44
The most obvious is the single point of failure that the centralized server represents.
46
45
If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything they're working on.
47
-
If the hard disk the central database is on becomes corrupted, and proper backups haven't been kept, you lose absolutely everything – the entire history of the project except whatever single snapshots people happen to have on their local machines.
48
-
Local VCS systems suffer from this same problem – whenever you have the entire history of the project in a single place, you risk losing everything.
46
+
If the hard disk the central database is on becomes corrupted, and proper backups haven't been kept, you lose absolutely everything -- the entire history of the project except whatever single snapshots people happen to have on their local machines.
47
+
Local VCSs suffer from this same problem -- whenever you have the entire history of the project in a single place, you risk losing everything.
49
48
50
49
==== Distributed Version Control Systems
51
50
52
51
(((version control,distributed)))
53
52
This is where Distributed Version Control Systems (DVCSs) step in.
54
-
In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files: they fully mirror the repository.
55
-
Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it.
53
+
In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history.
54
+
Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it.
56
55
Every clone is really a full backup of all the data.
57
56
58
-
.Distributed version control.
57
+
.Distributed version control
59
58
image::images/distributed.png[Distributed version control diagram]
60
59
61
60
Furthermore, many of these systems deal pretty well with having several remote repositories they can work with, so you can collaborate with different groups of people in different ways simultaneously within the same project.
There are the original commandline tools, and there are many graphical user interfaces of varying capabilities.
4
+
There are the original command-line tools, and there are many graphical user interfaces of varying capabilities.
5
5
For this book, we will be using Git on the command line.
6
-
For one, the command line is the only place you can run *all* Git commands – most of the GUIs only implement some subset of Git functionality for simplicity.
7
-
If you know how to run the commandline version, you can probably also figure out how to run the GUI version, while the opposite is not necessarily true.
6
+
For one, the command line is the only place you can run _all_ Git commands -- most of the GUIs implement only a partial subset of Git functionality for simplicity.
7
+
If you know how to run the command-line version, you can probably also figure out how to run the GUI version, while the opposite is not necessarily true.
8
8
Also, while your choice of graphical client is a matter of personal taste, _all_ users will have the command-line tools installed and available.
9
9
10
-
So we will expect you to know how to open Terminal in Mac or Command Prompt or Powershell in Windows.
10
+
So we will expect you to know how to open Terminal in macOS or Command Prompt or PowerShell in Windows.
11
11
If you don't know what we're talking about here, you may need to stop and research that quickly so that you can follow the rest of the examples and descriptions in this book.
Copy file name to clipboardExpand all lines: book-en/01-introduction/sections/first-time-setup.asc
+52-19Lines changed: 52 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,20 +8,30 @@ You can also change them at any time by running through the commands again.
8
8
Git comes with a tool called `git config` that lets you get and set configuration variables that control all aspects of how Git looks and operates.(((git commands, config)))
9
9
These variables can be stored in three different places:
10
10
11
-
1. `/etc/gitconfig` file: Contains values for every user on the system and all their repositories.
11
+
1. `[path]/etc/gitconfig` file: Contains values applied to every user on the system and all their repositories.
12
12
If you pass the option `--system` to `git config`, it reads and writes from this file specifically.
13
-
2. `~/.gitconfig` or `~/.config/git/config` file: Specific to your user.
14
-
You can make Git read and write to this file specifically by passing the `--global` option.
13
+
Because this is a system configuration file, you would need administrative or superuser privilege to make changes to it.
14
+
2. `~/.gitconfig` or `~/.config/git/config` file: Values specific personally to you, the user.
15
+
You can make Git read and write to this file specifically by passing the `--global` option, and this affects _all_ of the repositories you work with on your system.
15
16
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you're currently using: Specific to that single repository.
17
+
You can force Git to read from and write to this file with the `--local` option, but that is in fact the default.
18
+
Unsurprisingly, you need to be located somewhere in a Git repository for this option to work properly.
16
19
17
-
Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.
20
+
Each level overrides values in the previous level, so values in `.git/config` trump those in `[path]/etc/gitconfig`.
18
21
19
22
On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
20
-
It also still looks for `/etc/gitconfig`, although it's relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
23
+
It also still looks for `[path]/etc/gitconfig`, although it's relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
21
24
If you are using version 2.x or later of Git for Windows, there is also a system-level config file at
22
25
`C:\Documents and Settings\All Users\Application Data\Git\config` on Windows XP, and in `C:\ProgramData\Git\config` on Windows Vista and newer.
23
26
This config file can only be changed by `git config -f <file>` as an admin.
24
27
28
+
You can view all of your settings and where they are coming from using:
29
+
30
+
[source,console]
31
+
----
32
+
$ git config --list --show-origin
33
+
----
34
+
25
35
==== Your Identity
26
36
27
37
The first thing you should do when you install Git is to set your user name and email address.
@@ -38,6 +48,7 @@ If you want to override this with a different name or email address for specific
38
48
39
49
Many of the GUI tools will help you do this when you first run them.
40
50
51
+
[[_editor]]
41
52
==== Your Editor
42
53
43
54
Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message.
@@ -50,34 +61,44 @@ If you want to use a different text editor, such as Emacs, you can do the follow
50
61
$ git config --global core.editor emacs
51
62
----
52
63
53
-
While on a Windows system, if you want to use a different text editor, such as Notepad++, you can do the following:
64
+
On a Windows system, if you want to use a different text editor, you must specify the full path to its executable file.
65
+
This can be different depending on how your editor is packaged.
66
+
67
+
In the case of Notepad++, a popular programming editor, you are likely to want to use the 32-bit version, since at the time of writing the 64-bit version doesn't support all plug-ins.
68
+
If you are on a 32-bit Windows system, or you have a 64-bit editor on a 64-bit system, you'll type something like this:
Vim, Emacs and Notepad++ are popular text editors often used by developers on Unixbased systems like Linux and OS X or a Windows system.
69
-
If you are not familiar with either of these editors, you may need to search for specific instructions for how to set up your favorite editor with Git.
77
+
Vim, Emacs and Notepad++ are popular text editors often used by developers on Unix-based systems like Linux and macOS or a Windows system.
78
+
If you are using another editor, or a 32-bit version, please find specific instructions for how to set up your favorite editor with Git in <<C-git-commands#ch_core_editor>>.
70
79
====
71
80
72
81
[WARNING]
73
82
====
74
-
You may find, if you don't setup an editor like this, you will likely get into a really confusing state when they are launched.
75
-
Such example on a Windows system may include a prematurely terminated Git operation during a Git initiated edit.
83
+
You may find, if you don't setup your editor like this, you get into a really confusing state when Git attempts to launch it.
84
+
An example on a Windows system may include a prematurely terminated Git operation during a Git initiated edit.
76
85
====
77
86
87
+
==== Your default branch name
88
+
89
+
By default Git will create a branch called _master_ when you create a new repository with `git init`.
90
+
From Git version 2.28 onwards, you can set a different name for the initial branch.
91
+
92
+
To set _main_ as the default branch name do:
93
+
94
+
[source,console]
95
+
----
96
+
$ git config --global init.defaultBranch main
97
+
----
98
+
78
99
==== Checking Your Settings
79
100
80
-
If you want to check your settings, you can use the `git config --list` command to list all the settings Git can find at that point:
101
+
If you want to check your configuration settings, you can use the `git config --list` command to list all the settings Git can find at that point:
81
102
82
103
[source,console]
83
104
----
@@ -91,7 +112,7 @@ color.diff=auto
91
112
...
92
113
----
93
114
94
-
You may see keys more than once, because Git reads the same key from different files (`/etc/gitconfig` and `~/.gitconfig`, for example).
115
+
You may see keys more than once, because Git reads the same key from different files (`[path]/etc/gitconfig` and `~/.gitconfig`, for example).
95
116
In this case, Git uses the last value for each unique key it sees.
96
117
97
118
You can also check what Git thinks a specific key's value is by typing `git config <key>`:(((git commands, config)))
@@ -101,3 +122,15 @@ You can also check what Git thinks a specific key's value is by typing `git conf
101
122
$ git config user.name
102
123
John Doe
103
124
----
125
+
126
+
[NOTE]
127
+
====
128
+
Since Git might read the same configuration variable value from more than one file, it's possible that you have an unexpected value for one of these values and you don't know why.
129
+
In cases like that, you can query Git as to the _origin_ for that value, and it will tell you which configuration file had the final say in setting that value:
If you ever need help while using Git, there are three ways to get the manual page (manpage) help for any of the Git commands:
4
+
If you ever need help while using Git, there are three equivalent ways to get the comprehensive manual page (manpage) help for any of the Git commands:
5
5
6
6
[source,console]
7
7
----
@@ -10,13 +10,39 @@ $ git <verb> --help
10
10
$ man git-<verb>
11
11
----
12
12
13
-
For example, you can get the manpage help for the config command by running(((git commands, help)))
13
+
For example, you can get the manpage help for the `git config` command by running this:(((git commands, help)))
14
14
15
15
[source,console]
16
16
----
17
17
$ git help config
18
18
----
19
19
20
20
These commands are nice because you can access them anywhere, even offline.
21
-
If the manpages and this book aren't enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server (irc.freenode.net).
21
+
If the manpages and this book aren't enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server, which can be found at https://freenode.net[].
22
22
These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.(((IRC)))
23
+
24
+
In addition, if you don't need the full-blown manpage help, but just need a quick refresher on the available options for a Git command, you can ask for the more concise "`help`" output with the `-h` option, as in:
25
+
26
+
[source,console]
27
+
----
28
+
$ git add -h
29
+
usage: git add [<options>] [--] <pathspec>...
30
+
31
+
-n, --dry-run dry run
32
+
-v, --verbose be verbose
33
+
34
+
-i, --interactive interactive picking
35
+
-p, --patch select hunks interactively
36
+
-e, --edit edit current diff and apply
37
+
-f, --force allow adding otherwise ignored files
38
+
-u, --update update tracked files
39
+
--renormalize renormalize EOL of tracked files (implies -u)
40
+
-N, --intent-to-add record only the fact that the path will be added later
41
+
-A, --all add changes from all tracked and untracked files
42
+
--ignore-removal ignore paths removed in the working tree (same as --no-all)
43
+
--refresh don't add, only refresh the index
44
+
--ignore-errors just skip files which cannot be added because of errors
45
+
--ignore-missing check if - even missing - files are ignored in dry run
46
+
--chmod (+|-)x override the executable bit of the listed files
Copy file name to clipboardExpand all lines: book-en/01-introduction/sections/history.asc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,4 +17,4 @@ Some of the goals of the new system were as follows:
17
17
* Able to handle large projects like the Linux kernel efficiently (speed and data size)
18
18
19
19
Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities.
20
-
It's incredibly fast, it's very efficient with large projects, and it has an incredible branching system for non-linear development (See <<_git_branching>>).
20
+
It's amazingly fast, it's very efficient with large projects, and it has an incredible branching system for non-linear development (See <<ch03-git-branching#ch03-git-branching>>).
0 commit comments