summaryrefslogtreecommitdiffstats
path: root/web/input/doc
diff options
context:
space:
mode:
Diffstat (limited to 'web/input/doc')
-rw-r--r--web/input/doc/faq/git.md78
1 files changed, 40 insertions, 38 deletions
diff --git a/web/input/doc/faq/git.md b/web/input/doc/faq/git.md
index 53260ec..5503166 100644
--- a/web/input/doc/faq/git.md
+++ b/web/input/doc/faq/git.md
@@ -17,10 +17,10 @@ means distributed development can occur around that central repository.
17Git has an additional stage between the working directory and the repository. 17Git has an additional stage between the working directory and the repository.
18The idea is that you might be working on multiple unrelated things without 18The idea is that you might be working on multiple unrelated things without
19wanting to commit all changes in one go. Therefore, the changes that should 19wanting to commit all changes in one go. Therefore, the changes that should
20be committed must first be added to the repository *index*, which can be seen 20be committed must first be added to the so-called *index*, which can be seen
21as a staging area. This is usually done with **git add**, both for new files 21as a staging area of the repository. This is usually done with **git add**,
22*and* for changes to existing ones. When you commit using **git commit**, 22both for new files *and* for changes to existing ones. When you commit using
23only the changes in the index are considered. 23**git commit**, only the changes in the index are considered.
24 24
25After committing, the changes are still local. To share them with others, you 25After committing, the changes are still local. To share them with others, you
26have to push them to a remote repository, or have someone pull from your 26have to push them to a remote repository, or have someone pull from your
@@ -39,9 +39,9 @@ with Git you only have to type a handful of digits to reference one.
39## Cloning a Project 39## Cloning a Project
40 40
41To work on a project you first have to clone it. This creates your own local 41To work on a project you first have to clone it. This creates your own local
42repository and until you want to distribute your change or merge changes from 42repository, and until you want to distribute your change or merge changes from
43someone else everything that follows can happen offline. If you have push 43someone else, everything that follows can happen offline. If you have push
44access, run the command: 44access to the Nagios Plugins repository, run the command:
45 45
46 git clone git@github.com:nagios-plugins/nagios-plugins.git 46 git clone git@github.com:nagios-plugins/nagios-plugins.git
47 47
@@ -50,9 +50,9 @@ run this command instead:
50 50
51 git clone git://github.com/nagios-plugins/nagios-plugins.git 51 git clone git://github.com/nagios-plugins/nagios-plugins.git
52 52
53This will create a directory called `nagios-plugins` in your current directory 53This will create a directory called `nagios-plugins` with all the `master`
54with all the `master` code and history (this is roughly equivalent to CVS/SVN 54code and history (this is roughly equivalent to CVS/SVN `HEAD`). Change
55`HEAD`). Change directory to `nagios-plugins`. 55directory to `nagios-plugins`.
56 56
57## Editing Files 57## Editing Files
58 58
@@ -61,7 +61,7 @@ You can edit the files in the working area. To check the status, use:
61 git status 61 git status
62 62
63This will show a list of changes in the working directory. Newly made changes 63This will show a list of changes in the working directory. Newly made changes
64appear in *red*, while changes added to the index are shown in green. You can 64appear in red, while changes added to the index are shown in green. You can
65use **git diff** to see changes between the current working directory and the 65use **git diff** to see changes between the current working directory and the
66index (untracked files will not be shown). 66index (untracked files will not be shown).
67 67
@@ -70,25 +70,25 @@ index (untracked files will not be shown).
70Use **git add** to specify which new files/changes you want to commit; this 70Use **git add** to specify which new files/changes you want to commit; this
71will add the changes to the index. You can select only partial diffs with 71will add the changes to the index. You can select only partial diffs with
72**git add -p** too. If you want to commit everything you can use **git commit 72**git add -p** too. If you want to commit everything you can use **git commit
73-a** directly. You can see the changes you are about to commit (difference 73-a** directly. You can see the changes you are about to commit (the
74between HEAD and the index) with **git diff --cached**, and then commit them 74difference between HEAD and the index) with **git diff --staged**, and then
75with: 75commit them with:
76 76
77 git commit 77 git commit
78 78
79Add a comment (you have read the [Development Guidelines][guidelines], right? 79Add a comment (you *have* read the [Development Guidelines][guidelines],
80:-)). This commit will be local (affecting only your own repository) so you 80right? :-)). This commit will be local (affecting only your own repository),
81will have to either push your changes, or have someone to pull them from you 81so you will have to either push your changes, or have someone pull them from
82(in the latter case you will most likely still push to a publicly accessible 82you (in the latter case you will most likely still push to a publicly
83clone of your local repository). If the change is from a contributor, set the 83accessible clone of your local repository). If the change is from a
84author at commit time: 84contributor, set the author at commit time:
85 85
86 git commit --author="Jane Doe <jane@example.com>" 86 git commit --author="Jane Doe <jane@example.com>"
87 87
88If you realize that you forgot something in your commit and haven’t pushed it 88If you realize that you forgot something in your commit and haven’t pushed it
89yet to a remote repository, you can amend your last commit with **git commit 89yet to a remote repository, you can amend your last commit with **git commit
90--amend**. You can also amend after a push and force the next update, however 90--amend**. You can also amend after a push and force the next update, however
91this will cause non-linear updates and should be done only if the developers 91this will cause non-linear updates and should be done only if all developers
92using your repository are aware of it. 92using your repository are aware of it.
93 93
94## Reverting Local Modifications 94## Reverting Local Modifications
@@ -119,46 +119,46 @@ command you may be able to recover them with **git reflog** and **git checkout
119 git reset --hard <file> 119 git reset --hard <file>
120 120
121Do not reset changes that have already been pushed to remote repositories as 121Do not reset changes that have already been pushed to remote repositories as
122this will cause non-linear updates. If you do so, developers using those 122this will cause non-linear updates. If you do so, all developers using those
123repositories should be aware of it. 123repositories should be aware of it.
124 124
125## Merging Remote Changes 125## Merging Remote Changes
126 126
127When you work on your local repository you’ll need to keep it up to date with 127When you work on your local repository you’ll need to keep it up to date with
128the development tree. This is very similar to **svn update** with the 128the development tree. This is very similar to **svn update**, with the
129difference that it can’t be done if the working tree has any unmerged changes. 129difference that it can’t be done if the working tree has any unmerged changes.
130If you do, either commit them or put them aside (Tip: **git stash**). If you 130If you do, either commit them or put them aside (hint: **git stash**). If you
131cloned from the main Git repository, this command will do a fetch then merge 131cloned from the main Git repository, this command will do a fetch and then
132any new changes: 132merge any new changes:
133 133
134 git pull 134 git pull
135 135
136You can also merge changes from any other fork of the repository. This 136You can also merge changes from any other fork of the repository. This
137usually happens if someone ask you to pull from his own repo for some fix or 137usually happens if someone asks you to pull from his own repo for some fix or
138enhancements. Together with **--no-commit** you will have a chance to review 138enhancements. Together with **--no-commit**, you will have a chance to review
139the changes and make any relevant correction before the merge. Example: 139the changes and make any relevant correction before the merge. Example:
140 140
141 git pull --no-commit git://example.com/path/to/repo.git master 141 git pull --no-commit git://example.com/path/to/repo.git master
142 142
143## Merging Back to the Main Repository 143## Merging Back to the Main Repository
144 144
145Once you’re done with your commits and after pulling from the main repository, 145Once you’re done with your commits, and after pulling from the main
146you can push you change back to it. If you cloned using the *push* url this 146repository, you can push your changes back to it. If you cloned using the
147command will push the master branch: 147*push* URL, this command will push the master branch:
148 148
149 git push 149 git push
150 150
151It you’re trying to push something that would generate merge conflicts, the 151It you’re trying to push something that would generate merge conflicts, the
152push will be rejected. You will have yo do a pull first, fix the any 152push will be rejected. You will have to do a pull first, fix any conflicts
153conflicts locally and then push again. If your commits are local (you haven’t 153locally, and then push again. If your commits are local (you haven’t pulled
154pulled them from someone else or published them somewhere) you can rebase to 154them from someone else or published them somewhere) you can rebase to avoid a
155avoid a merge: 155merge:
156 156
157 git pull --rebase 157 git pull --rebase
158 158
159Like a merge, this may generate conflicts and let you fix them, but instead of 159Like a merge, this may generate conflicts and let you fix them, but instead of
160creating a merge commit on top of the others, it will undo your commits, 160creating a merge commit on top of the others, it will undo your commits,
161fast-forward and apply your commits again. This is cleaner but doesn’t play 161fast-forward and apply your commits again. This is cleaner, but doesn’t play
162well when it rewrites already published history. 162well when it rewrites already published history.
163 163
164## Going Further 164## Going Further
@@ -168,7 +168,8 @@ commands for manipulating changes and working with others. They are all very
168well documented (see **git help [-a]** for a list of commands, **git help 168well documented (see **git help [-a]** for a list of commands, **git help
169<cmd\>** or **git <cmd\> --help** shows the man page). You might also want to 169<cmd\>** or **git <cmd\> --help** shows the man page). You might also want to
170look into some of the references listed below, or into a book such as [Scott 170look into some of the references listed below, or into a book such as [Scott
171Chacon][scott]'s [Pro Git][book]. 171Chacon][scott]'s [Pro Git][book-home] (which is [freely available][book-free]
172on the [Git web site][git]).
172 173
173## References 174## References
174 175
@@ -195,6 +196,7 @@ Chacon][scott]'s [Pro Git][book].
195[guidelines]: doc/guidelines.html "Nagios Plugin Development Guidelines" 196[guidelines]: doc/guidelines.html "Nagios Plugin Development Guidelines"
196[git]: http://git-scm.com/ "Git" 197[git]: http://git-scm.com/ "Git"
197[scott]: http://scottchacon.com/ "Scott Chacon" 198[scott]: http://scottchacon.com/ "Scott Chacon"
198[book]: http://git-scm.com/book "Pro Git" 199[book-home]: http://www.apress.com/9781430218333 "Pro Git at Apress"
200[book-free]: http://git-scm.com/book "Pro Git for Free"
199 201
200<!--% # vim:set filetype=markdown textwidth=78 joinspaces: # %--> 202<!--% # vim:set filetype=markdown textwidth=78 joinspaces: # %-->