| | 96 | |
| | 97 | For short tasks that one expects to complete before moving on to others, a developer may use the '''develop''' branch (in his own repository) directly, rather than creating a feature branch (see next section). The example below shows a file being added to the repositories. Note that modifying a file uses exactly the same steps '''git'''-wise. |
| | 98 | |
| | 99 | A few items of note: |
| | 100 | - the '''add''' command ''__stage__s'' a file, which means that the repository version of the file will be updated ''__with the current contents of the working file__'' at the next '''commit'''. |
| | 101 | - '''git diff''' may be used to compare the working file with either the staged (using no extra arguments) or the committed (using the '''HEAD''' argument) file. |
| | 102 | - files may be reverted to the staged version by using the '''checkout''' command. |
| | 103 | - to unstage a file and return to the committed file, use the '''reset''' command. |
| | 104 | - a '''pull''' is usually done before a '''commit''' so that changes committed by others may be incorporated immediately rather than as part of a ''merge commit''. |
| | 105 | - the '''-a''' flag to '''commit''' is used to stage the latest version of changes before committing. This is different from '''svn''' where '''commit'''ting a file always commits the latest version. In '''git''', a '''commit''' commits the version of the file ''__at the time that it was staged__''; subsequent changes will not be committed unless the file is explicitly staged again using the '''add''' command or the '''-a''' flag is specified for the '''commit''' command. |
| | 106 | - the '''-m''' flag to commit specifies a log message for the commit. To use longer log messages, omit the '''-m''' flag and a text editor (from environment variable '''EDITOR''') will automatically start. |
| | 107 | - the '''commit''' command only updates the local repository. To make changes visible to other developers, do not forget to '''push''' as well. |
| | 108 | |
| | 109 | {{{#!html |
| | 110 | <pre style="margin-left:20px; margin-right:20px; border:solid 1px; padding:3px; background:white;"> |
| | 111 | <b style="color:#c22;">franklin:myrepo conrad$ pwd</b> |
| | 112 | /usr/local/projects/chimera2/git/myrepo |
| | 113 | <b style="color:#c22;">franklin:myrepo conrad$ git status</b> |
| | 114 | # On branch develop |
| | 115 | nothing to commit (working directory clean) |
| | 116 | <b style="color:#c22;">franklin:myrepo conrad$ echo "hello world" > example</b> |
| | 117 | <b style="color:#c22;">franklin:myrepo conrad$ git status</b> |
| | 118 | # On branch develop |
| | 119 | # Untracked files: |
| | 120 | # (use "git add <file>..." to include in what will be committed) |
| | 121 | # |
| | 122 | # example |
| | 123 | nothing added to commit but untracked files present (use "git add" to track) |
| | 124 | <b style="color:#c22;">franklin:myrepo conrad$ git add example</b> |
| | 125 | <b style="color:#c22;">franklin:myrepo conrad$ git status</b> |
| | 126 | # On branch develop |
| | 127 | # Changes to be committed: |
| | 128 | # (use "git reset HEAD <file>..." to unstage) |
| | 129 | # |
| | 130 | # new file: example |
| | 131 | # |
| | 132 | <b style="color:#c22;">franklin:myrepo conrad$ git diff</b> |
| | 133 | <b style="color:#c22;">franklin:myrepo conrad$ echo "hello conrad" > example</b> |
| | 134 | <b style="color:#c22;">franklin:myrepo conrad$ git diff</b> |
| | 135 | diff --git a/example b/example |
| | 136 | index 3b18e51..d21055a 100644 |
| | 137 | --- a/example |
| | 138 | +++ b/example |
| | 139 | @@ -1 +1 @@ |
| | 140 | -hello world |
| | 141 | +hello conrad |
| | 142 | <b style="color:#c22;">franklin:myrepo conrad$ git checkout example</b> |
| | 143 | <b style="color:#c22;">franklin:myrepo conrad$ cat example</b> |
| | 144 | hello world |
| | 145 | <b style="color:#c22;">franklin:myrepo conrad$ git diff HEAD</b> |
| | 146 | diff --git a/example b/example |
| | 147 | new file mode 100644 |
| | 148 | index 0000000..3b18e51 |
| | 149 | --- /dev/null |
| | 150 | +++ b/example |
| | 151 | @@ -0,0 +1 @@ |
| | 152 | +hello world |
| | 153 | <b style="color:#c22;">franklin:myrepo conrad$ echo "hello chimera2" > example</b> |
| | 154 | <b style="color:#c22;">franklin:myrepo conrad$ git diff</b> |
| | 155 | diff --git a/example b/example |
| | 156 | index 3b18e51..addaf36 100644 |
| | 157 | --- a/example |
| | 158 | +++ b/example |
| | 159 | @@ -1 +1 @@ |
| | 160 | -hello world |
| | 161 | +hello chimera2 |
| | 162 | <b style="color:#c22;">franklin:myrepo conrad$ git pull</b> |
| | 163 | Already up-to-date. |
| | 164 | <b style="color:#c22;">franklin:myrepo conrad$ git commit -a -m "example"</b> |
| | 165 | [develop a3108a9] example |
| | 166 | 1 files changed, 1 insertions(+), 0 deletions(-) |
| | 167 | create mode 100644 example |
| | 168 | <b style="color:#c22;">franklin:myrepo conrad$ git push</b> |
| | 169 | Counting objects: 4, done. |
| | 170 | Delta compression using up to 64 threads. |
| | 171 | Compressing objects: 100% (2/2), done. |
| | 172 | Writing objects: 100% (3/3), 278 bytes, done. |
| | 173 | Total 3 (delta 1), reused 0 (delta 0) |
| | 174 | Unpacking objects: 100% (3/3), done. |
| | 175 | To /usr/local/projects/chimera2/git/chimera2.git |
| | 176 | 1d973d7..a3108a9 develop -> develop |
| | 177 | </pre> |
| | 178 | }}} |
| | 179 | |