diff options
Diffstat (limited to 'web/input/doc/faq/git.md')
-rw-r--r-- | web/input/doc/faq/git.md | 78 |
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. | |||
17 | Git has an additional stage between the working directory and the repository. | 17 | Git has an additional stage between the working directory and the repository. |
18 | The idea is that you might be working on multiple unrelated things without | 18 | The idea is that you might be working on multiple unrelated things without |
19 | wanting to commit all changes in one go. Therefore, the changes that should | 19 | wanting to commit all changes in one go. Therefore, the changes that should |
20 | be committed must first be added to the repository *index*, which can be seen | 20 | be committed must first be added to the so-called *index*, which can be seen |
21 | as a staging area. This is usually done with **git add**, both for new files | 21 | as 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**, | 22 | both for new files *and* for changes to existing ones. When you commit using |
23 | only the changes in the index are considered. | 23 | **git commit**, only the changes in the index are considered. |
24 | 24 | ||
25 | After committing, the changes are still local. To share them with others, you | 25 | After committing, the changes are still local. To share them with others, you |
26 | have to push them to a remote repository, or have someone pull from your | 26 | have 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 | ||
41 | To work on a project you first have to clone it. This creates your own local | 41 | To work on a project you first have to clone it. This creates your own local |
42 | repository and until you want to distribute your change or merge changes from | 42 | repository, and until you want to distribute your change or merge changes from |
43 | someone else everything that follows can happen offline. If you have push | 43 | someone else, everything that follows can happen offline. If you have push |
44 | access, run the command: | 44 | access 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 | ||
53 | This will create a directory called `nagios-plugins` in your current directory | 53 | This will create a directory called `nagios-plugins` with all the `master` |
54 | with all the `master` code and history (this is roughly equivalent to CVS/SVN | 54 | code and history (this is roughly equivalent to CVS/SVN `HEAD`). Change |
55 | `HEAD`). Change directory to `nagios-plugins`. | 55 | directory 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 | ||
63 | This will show a list of changes in the working directory. Newly made changes | 63 | This will show a list of changes in the working directory. Newly made changes |
64 | appear in *red*, while changes added to the index are shown in green. You can | 64 | appear in red, while changes added to the index are shown in green. You can |
65 | use **git diff** to see changes between the current working directory and the | 65 | use **git diff** to see changes between the current working directory and the |
66 | index (untracked files will not be shown). | 66 | index (untracked files will not be shown). |
67 | 67 | ||
@@ -70,25 +70,25 @@ index (untracked files will not be shown). | |||
70 | Use **git add** to specify which new files/changes you want to commit; this | 70 | Use **git add** to specify which new files/changes you want to commit; this |
71 | will add the changes to the index. You can select only partial diffs with | 71 | will 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 |
74 | between HEAD and the index) with **git diff --cached**, and then commit them | 74 | difference between HEAD and the index) with **git diff --staged**, and then |
75 | with: | 75 | commit them with: |
76 | 76 | ||
77 | git commit | 77 | git commit |
78 | 78 | ||
79 | Add a comment (you have read the [Development Guidelines][guidelines], right? | 79 | Add a comment (you *have* read the [Development Guidelines][guidelines], |
80 | :-)). This commit will be local (affecting only your own repository) so you | 80 | right? :-)). This commit will be local (affecting only your own repository), |
81 | will have to either push your changes, or have someone to pull them from you | 81 | so 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 | 82 | you (in the latter case you will most likely still push to a publicly |
83 | clone of your local repository). If the change is from a contributor, set the | 83 | accessible clone of your local repository). If the change is from a |
84 | author at commit time: | 84 | contributor, 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 | ||
88 | If you realize that you forgot something in your commit and haven’t pushed it | 88 | If you realize that you forgot something in your commit and haven’t pushed it |
89 | yet to a remote repository, you can amend your last commit with **git commit | 89 | yet 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 |
91 | this will cause non-linear updates and should be done only if the developers | 91 | this will cause non-linear updates and should be done only if all developers |
92 | using your repository are aware of it. | 92 | using 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 | ||
121 | Do not reset changes that have already been pushed to remote repositories as | 121 | Do not reset changes that have already been pushed to remote repositories as |
122 | this will cause non-linear updates. If you do so, developers using those | 122 | this will cause non-linear updates. If you do so, all developers using those |
123 | repositories should be aware of it. | 123 | repositories should be aware of it. |
124 | 124 | ||
125 | ## Merging Remote Changes | 125 | ## Merging Remote Changes |
126 | 126 | ||
127 | When you work on your local repository you’ll need to keep it up to date with | 127 | When you work on your local repository you’ll need to keep it up to date with |
128 | the development tree. This is very similar to **svn update** with the | 128 | the development tree. This is very similar to **svn update**, with the |
129 | difference that it can’t be done if the working tree has any unmerged changes. | 129 | difference that it can’t be done if the working tree has any unmerged changes. |
130 | If you do, either commit them or put them aside (Tip: **git stash**). If you | 130 | If you do, either commit them or put them aside (hint: **git stash**). If you |
131 | cloned from the main Git repository, this command will do a fetch then merge | 131 | cloned from the main Git repository, this command will do a fetch and then |
132 | any new changes: | 132 | merge any new changes: |
133 | 133 | ||
134 | git pull | 134 | git pull |
135 | 135 | ||
136 | You can also merge changes from any other fork of the repository. This | 136 | You can also merge changes from any other fork of the repository. This |
137 | usually happens if someone ask you to pull from his own repo for some fix or | 137 | usually happens if someone asks you to pull from his own repo for some fix or |
138 | enhancements. Together with **--no-commit** you will have a chance to review | 138 | enhancements. Together with **--no-commit**, you will have a chance to review |
139 | the changes and make any relevant correction before the merge. Example: | 139 | the 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 | ||
145 | Once you’re done with your commits and after pulling from the main repository, | 145 | Once you’re done with your commits, and after pulling from the main |
146 | you can push you change back to it. If you cloned using the *push* url this | 146 | repository, you can push your changes back to it. If you cloned using the |
147 | command 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 | ||
151 | It you’re trying to push something that would generate merge conflicts, the | 151 | It you’re trying to push something that would generate merge conflicts, the |
152 | push will be rejected. You will have yo do a pull first, fix the any | 152 | push will be rejected. You will have to do a pull first, fix any conflicts |
153 | conflicts locally and then push again. If your commits are local (you haven’t | 153 | locally, and then push again. If your commits are local (you haven’t pulled |
154 | pulled them from someone else or published them somewhere) you can rebase to | 154 | them from someone else or published them somewhere) you can rebase to avoid a |
155 | avoid a merge: | 155 | merge: |
156 | 156 | ||
157 | git pull --rebase | 157 | git pull --rebase |
158 | 158 | ||
159 | Like a merge, this may generate conflicts and let you fix them, but instead of | 159 | Like a merge, this may generate conflicts and let you fix them, but instead of |
160 | creating a merge commit on top of the others, it will undo your commits, | 160 | creating a merge commit on top of the others, it will undo your commits, |
161 | fast-forward and apply your commits again. This is cleaner but doesn’t play | 161 | fast-forward and apply your commits again. This is cleaner, but doesn’t play |
162 | well when it rewrites already published history. | 162 | well 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 | |||
168 | well documented (see **git help [-a]** for a list of commands, **git help | 168 | well 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 |
170 | look into some of the references listed below, or into a book such as [Scott | 170 | look into some of the references listed below, or into a book such as [Scott |
171 | Chacon][scott]'s [Pro Git][book]. | 171 | Chacon][scott]'s [Pro Git][book-home] (which is [freely available][book-free] |
172 | on 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: # %--> |