author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Fri, 14 Oct 2011 00:48:05 +0300 | |
changeset 1032 | 4decc3e00bb6 |
parent 1002 | 234cd58cae56 |
child 1076 | 9b2eb3c96d84 |
permissions | -rw-r--r-- |
1002 | 1 |
.. -*- coding: utf-8; -*- |
2 |
||
3 |
====== |
|
4 |
Git. |
|
5 |
====== |
|
1032
4decc3e00bb6
Fix coding and contents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1002
diff
changeset
|
6 |
.. contents:: |
1002 | 7 |
|
8 |
Setup git. |
|
9 |
========== |
|
10 |
||
11 |
Debian. |
|
12 |
------- |
|
13 |
||
14 |
For Etch Degian release use git-core package from backports, |
|
15 |
old 1.4 version of git very dumb compared to new version 1.5:: |
|
16 |
||
17 |
$ sudo apt-get install git-core |
|
18 |
||
19 |
After install setup some options:: |
|
20 |
||
21 |
$ git config --global user.name "Oleksandr Gavenko" |
|
22 |
$ git config --global user.mail "gavenkoa@gmail.com" |
|
23 |
$ cat ~/.gitconfig |
|
24 |
[user] |
|
25 |
name = Oleksandr Gavenko |
|
26 |
mail = gavenkoa@gmail.com |
|
27 |
||
28 |
Windows. |
|
29 |
-------- |
|
30 |
||
31 |
No official support for Windows OS. |
|
32 |
||
33 |
Cygwin. |
|
34 |
------- |
|
35 |
||
36 |
$ setup.exe -p git |
|
37 |
||
38 |
git over proxy. |
|
39 |
=============== |
|
40 |
||
41 |
Only http:// protocol support proxy (not git://):: |
|
42 |
||
43 |
$ export http_proxy="http://username:password@proxy:port/" |
|
44 |
$ git clone http://github.com/$user/$proj.git $proj |
|
45 |
||
46 |
You can store proxy settings under repository local config file:: |
|
47 |
||
48 |
$ git config http.proxy http://$user:$passwd@$ip:$port |
|
49 |
||
50 |
Start your project. |
|
51 |
=================== |
|
52 |
||
53 |
Setup proj space on fs:: |
|
54 |
||
55 |
$ mkdir proj |
|
56 |
$ cd proj |
|
57 |
$ git init |
|
58 |
Initialized empty Git repository in /home/user/tmp/proj/.git/ |
|
59 |
$ ls -a |
|
60 |
. .. .git |
|
61 |
||
62 |
Add file, make changes, commit all:: |
|
63 |
||
64 |
$ emacs Makefile |
|
65 |
... C-x C-c |
|
66 |
$ emacs app.c |
|
67 |
... C-x C-c |
|
68 |
$ git add Makefile app.c |
|
69 |
$ git status |
|
70 |
# On branch master |
|
71 |
# |
|
72 |
# Initial commit |
|
73 |
# |
|
74 |
# Changes to be committed: |
|
75 |
# (use "git rm --cached <file>..." to unstage) |
|
76 |
# |
|
77 |
# new file: Makefile |
|
78 |
# new file: app.c |
|
79 |
# |
|
80 |
||
81 |
or just:: |
|
82 |
||
83 |
$ git add . |
|
84 |
||
85 |
Commit newlly added file:: |
|
86 |
||
87 |
$ git commit |
|
88 |
... Write message log ... |
|
89 |
Created initial commit 2169263: My first commit massage. |
|
90 |
1 files changed, 4 insertions(+), 0 deletions(-) |
|
91 |
create mode 100644 app.c |
|
92 |
||
93 |
Undo tracking added file. |
|
94 |
========================= |
|
95 |
||
96 |
You do:: |
|
97 |
||
98 |
$ git add badfile |
|
99 |
$ git status |
|
100 |
# On branch master |
|
101 |
# Changes to be committed: |
|
102 |
# (use "git reset HEAD <file>..." to unstage) |
|
103 |
# |
|
104 |
# new file: badfile |
|
105 |
# |
|
106 |
||
107 |
To stop tracking badfile do:: |
|
108 |
||
109 |
$ git rm --cached badfile |
|
110 |
$ git status |
|
111 |
# On branch master |
|
112 |
# Untracked files: |
|
113 |
# (use "git add <file>..." to include in what will be committed) |
|
114 |
# |
|
115 |
# file |
|
116 |
nothing added to commit but untracked files present (use "git add" to track) |
|
117 |
||
118 |
or:: |
|
119 |
||
120 |
$ git reset badfile |
|
121 |
||
122 |
Doing changes. |
|
123 |
============== |
|
124 |
:: |
|
125 |
||
126 |
$ printf "clean:\n<TAB>rm $(wildcard *.o)\n" >>Makefile |
|
127 |
$ git diff |
|
128 |
diff --git a/Makefile b/Makefile |
|
129 |
index e84f7e9..cd2438a 100644 |
|
130 |
--- a/Makefile |
|
131 |
+++ b/Makefile |
|
132 |
@@ -1,2 +1,5 @@ |
|
133 |
all: |
|
134 |
@echo XXX |
|
135 |
exit 1 |
|
136 |
+ |
|
137 |
+clean: |
|
138 |
+ rm -f *.o |
|
139 |
$ git add Makefile |
|
140 |
$ git commit -m "Added clean target." |
|
141 |
Created commit 11272b9: Added clean target. |
|
142 |
1 files changed, 1 insertions(+), 0 deletions(-) |
|
143 |
create mode 100644 file |
|
144 |
||
145 |
or just:: |
|
146 |
||
147 |
$ git commit -a -m "Added clean target." |
|
148 |
||
149 |
git analog of 'hg incoming'. |
|
150 |
============================ |
|
151 |
||
152 |
git does not directly support such feature. You can emulate it by:: |
|
153 |
||
154 |
$ git fetch |
|
155 |
$ git log master..origin/master # or just '..origin/master' |
|
156 |
||
157 |
By previous commands you grab changes from remote server! You can apply them:: |
|
158 |
||
159 |
TODO |
|
160 |
$ git merge |
|
161 |
||
162 |
git analog of 'hg outgoing'. |
|
163 |
============================ |
|
164 |
||
165 |
git does not directly support such feature. You can emulate it by:: |
|
166 |
||
167 |
$ git fetch |
|
168 |
$ git log origin/master..master # or just 'origin/master..' |
|
169 |
||
170 |
Debug git network operation. |
|
171 |
============================ |
|
172 |
||
173 |
Git uses libcurl for network operation:: |
|
174 |
||
175 |
$ export GIT_CURL_VERBOSE=1 |
|
176 |
$ git ... |
|
177 |
||
178 |
Using git to work with SVN offline. |
|
179 |
=================================== |
|
180 |
||
181 |
Prepare SVN and git utilities:: |
|
182 |
||
183 |
$ sudo apt-get svn git-core git-svn |
|
184 |
||
185 |
Making SVN repo:: |
|
186 |
||
187 |
$ cd $HOME/tmp |
|
188 |
$ svnadmin create svn-repo |
|
189 |
$ svn co file://$HOME/tmp/svn-repo svn-devel |
|
190 |
$ cd svn-devel |
|
191 |
$ mkdir tags trunk branches |
|
192 |
$ svn add * |
|
193 |
A branches |
|
194 |
A tags |
|
195 |
A trunk |
|
196 |
$ cd trunk/ |
|
197 |
$ printf "all:\n echo XXX\n" >Makefile |
|
198 |
$ printf "int main() {return 0;}" >main.c |
|
199 |
$ svn add * |
|
200 |
$ cd .. |
|
201 |
$ svn st |
|
202 |
A trunk |
|
203 |
A trunk/main.c |
|
204 |
A trunk/Makefile |
|
205 |
A branches |
|
206 |
A tags |
|
207 |
$ svn ci -m init |
|
208 |
Adding branches |
|
209 |
Adding tags |
|
210 |
Adding trunk |
|
211 |
Adding trunk/Makefile |
|
212 |
Adding trunk/main.c |
|
213 |
Transmitting file data .. |
|
214 |
$ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
215 |
$ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
216 |
||
217 |
Moving SVN changset to git repo:: |
|
218 |
||
219 |
$ cd $HOME/tmp |
|
220 |
$ git svn init file://$HOME/tmp/svn git-repo |
|
221 |
$ ls -a |
|
222 |
. .. .git |
|
223 |
$ git svn fetch |
|
224 |
A trunk/main.c |
|
225 |
A trunk/Makefile |
|
226 |
W: +empty_dir: branches |
|
227 |
W: +empty_dir: tags |
|
228 |
r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
229 |
A tags/v0.0/main.c |
|
230 |
A tags/v0.0/Makefile |
|
231 |
r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
232 |
M trunk/Makefile |
|
233 |
r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
234 |
A branches/v0.1/main.c |
|
235 |
A branches/v0.1/Makefile |
|
236 |
r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
237 |
M trunk/Makefile |
|
238 |
r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
239 |
Checked out HEAD: |
|
240 |
file:///home/sasha/tmp/svn r5 |
|
241 |
||
242 |
or (in old git version):: |
|
243 |
||
244 |
$ git svn clone file://$HOME/tmp/svn git-repo |
|
245 |
||
246 |
Making changes in svn:: |
|
247 |
||
248 |
$ cd $HOME/tmp/svn-devel/trunk |
|
249 |
$ echo ".PHONY: clean" >>Makefile |
|
250 |
$ svn ci -m "Added clean to phony." |
|
251 |
Sending trunk/Makefile |
|
252 |
Transmitting file data . |
|
253 |
Committed revision 6. |
|
254 |
||
255 |
Making committed in git:: |
|
256 |
||
257 |
$ cd $HOME/tmp/git-repo/trunk |
|
258 |
$ echo ".PHONY: all" >>Makefile |
|
259 |
$ echo "int foo(int x) {return x+x;}" >>main.c |
|
260 |
$ git status |
|
261 |
# On branch master |
|
262 |
# Changed but not updated: |
|
263 |
# (use "git add <file>..." to update what will be committed) |
|
264 |
# |
|
265 |
# modified: Makefile |
|
266 |
# modified: main.c |
|
267 |
# |
|
268 |
no changes added to commit (use "git add" and/or "git commit -a") |
|
269 |
$ git commit -a -m "Bug fixed." |
|
270 |
Created commit 222d399: Bug fixed. |
|
271 |
2 files changed, 2 insertions(+), 0 deletions(-) |
|
272 |
||
273 |
Getting changes from SVN to git:: |
|
274 |
||
275 |
$ git svn rebase |
|
276 |
M trunk/Makefile |
|
277 |
r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
|
278 |
First, rewinding head to replay your work on top of it... |
|
279 |
Applying Bug fixed. |
|
280 |
error: patch failed: trunk/Makefile:6 |
|
281 |
error: trunk/Makefile: patch does not apply |
|
282 |
Using index info to reconstruct a base tree... |
|
283 |
Falling back to patching base and 3-way merge... |
|
284 |
Auto-merged trunk/Makefile |
|
285 |
CONFLICT (content): Merge conflict in trunk/Makefile |
|
286 |
Failed to merge in the changes. |
|
287 |
Patch failed at 0001. |
|
288 |
||
289 |
When you have resolved this problem run "git rebase --continue". |
|
290 |
If you would prefer to skip this patch, instead run "git rebase --skip". |
|
291 |
To restore the original branch and stop rebasing run "git rebase --abort". |
|
292 |
||
293 |
rebase refs/remotes/git-svn: command returned error: 1 |
|
294 |
$ git add Makefile |
|
295 |
$ git rebase --continue |
|
296 |
Applying Bug fixed. |
|
297 |
||
298 |
and return all from git to SVN:: |
|
299 |
||
300 |
$ git svn dcommit |
|
301 |
Committing to file:///home/sasha/tmp/svn ... |
|
302 |
M trunk/Makefile |
|
303 |
M trunk/main.c |
|
304 |
Committed r7 |
|
305 |
M trunk/main.c |
|
306 |
M trunk/Makefile |
|
307 |
r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
308 |
No changes between current HEAD and refs/remotes/git-svn |
|
309 |
Resetting to the latest refs/remotes/git-svn |
|
310 |
||
311 |
See what going to SVN repo:: |
|
312 |
||
313 |
$ cd $HOME/tmp/svn-devel/trunk |
|
314 |
$ svn diff -r BASE:HEAD |
|
315 |
Index: Makefile |
|
316 |
=================================================================== |
|
317 |
--- Makefile (working copy) |
|
318 |
+++ Makefile (revision 7) |
|
319 |
@@ -6,4 +6,4 @@ |
|
320 |
.o: .c |
|
321 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
322 |
||
323 |
-.PHONY: clean |
|
324 |
+.PHONY: all clean |
|
325 |
Index: main.c |
|
326 |
=================================================================== |
|
327 |
--- main.c (working copy) |
|
328 |
+++ main.c (revision 7) |
|
329 |
@@ -2,3 +2,4 @@ |
|
330 |
{ |
|
331 |
return 0; |
|
332 |
} |
|
333 |
+int foo(int x) {return x+x;} |
|
334 |
$ svn up |
|
335 |
U Makefile |
|
336 |
U main.c |
|
337 |
Updated to revision 7. |
|
338 |
||
339 |
gitk. |
|
340 |
===== |
|
341 |
||
342 |
gitk - The git repository browser. See gitk(1). |
|
343 |
||
344 |
Installing:: |
|
345 |
||
346 |
$ sudo apt-get instal gitk |
|
347 |
||
348 |
Using:: |
|
349 |
||
350 |
$ cd /path/to/git-repo |
|
351 |
$ gitk |
|
352 |