author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 18 Feb 2017 14:02:20 +0200 | |
changeset 2090 | 1a788101d63c |
parent 2085 | 652aca73fc06 |
child 2101 | 325b195030bd |
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:: |
1905
fba288d59662
Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1815
diff
changeset
|
7 |
:local: |
1002 | 8 |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
9 |
Setup git |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
10 |
========= |
1002 | 11 |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
12 |
Debian |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
13 |
------ |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
14 |
:: |
1002 | 15 |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
16 |
$ sudo apt-get install git |
1002 | 17 |
|
18 |
After install setup some options:: |
|
19 |
||
20 |
$ git config --global user.name "Oleksandr Gavenko" |
|
21 |
$ git config --global user.mail "gavenkoa@gmail.com" |
|
22 |
$ cat ~/.gitconfig |
|
23 |
[user] |
|
24 |
name = Oleksandr Gavenko |
|
25 |
mail = gavenkoa@gmail.com |
|
26 |
||
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
27 |
Cygwin |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
28 |
------ |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
29 |
:: |
1002 | 30 |
|
31 |
$ setup.exe -p git |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
32 |
$ apt-cyg install git |
1002 | 33 |
|
34 |
git over proxy. |
|
35 |
=============== |
|
36 |
||
37 |
Only http:// protocol support proxy (not git://):: |
|
38 |
||
39 |
$ export http_proxy="http://username:password@proxy:port/" |
|
40 |
$ git clone http://github.com/$user/$proj.git $proj |
|
41 |
||
42 |
You can store proxy settings under repository local config file:: |
|
43 |
||
44 |
$ git config http.proxy http://$user:$passwd@$ip:$port |
|
45 |
||
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
46 |
Start project with git |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
47 |
====================== |
1002 | 48 |
|
49 |
Setup proj space on fs:: |
|
50 |
||
51 |
$ mkdir proj |
|
52 |
$ cd proj |
|
53 |
$ git init |
|
54 |
Initialized empty Git repository in /home/user/tmp/proj/.git/ |
|
55 |
$ ls -a |
|
56 |
. .. .git |
|
57 |
||
58 |
Add file, make changes, commit all:: |
|
59 |
||
60 |
$ emacs Makefile |
|
61 |
... C-x C-c |
|
62 |
$ emacs app.c |
|
63 |
... C-x C-c |
|
64 |
$ git add Makefile app.c |
|
65 |
$ git status |
|
66 |
# On branch master |
|
67 |
# |
|
68 |
# Initial commit |
|
69 |
# |
|
70 |
# Changes to be committed: |
|
71 |
# (use "git rm --cached <file>..." to unstage) |
|
72 |
# |
|
73 |
# new file: Makefile |
|
74 |
# new file: app.c |
|
75 |
# |
|
76 |
||
77 |
or just:: |
|
78 |
||
79 |
$ git add . |
|
80 |
||
81 |
Commit newlly added file:: |
|
82 |
||
83 |
$ git commit |
|
84 |
... Write message log ... |
|
85 |
Created initial commit 2169263: My first commit massage. |
|
86 |
1 files changed, 4 insertions(+), 0 deletions(-) |
|
87 |
create mode 100644 app.c |
|
88 |
||
89 |
Undo tracking added file. |
|
90 |
========================= |
|
91 |
||
92 |
You do:: |
|
93 |
||
94 |
$ git add badfile |
|
95 |
$ git status |
|
96 |
# On branch master |
|
97 |
# Changes to be committed: |
|
98 |
# (use "git reset HEAD <file>..." to unstage) |
|
99 |
# |
|
100 |
# new file: badfile |
|
101 |
# |
|
102 |
||
103 |
To stop tracking badfile do:: |
|
104 |
||
105 |
$ git rm --cached badfile |
|
106 |
$ git status |
|
107 |
# On branch master |
|
108 |
# Untracked files: |
|
109 |
# (use "git add <file>..." to include in what will be committed) |
|
110 |
# |
|
111 |
# file |
|
112 |
nothing added to commit but untracked files present (use "git add" to track) |
|
113 |
||
114 |
or:: |
|
115 |
||
116 |
$ git reset badfile |
|
117 |
||
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
118 |
Committing changes |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
119 |
================== |
1002 | 120 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
121 |
Individual file:: |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
122 |
|
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
123 |
$ $EDITOR Makefile |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
124 |
$ git add Makefile |
1002 | 125 |
$ git diff |
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
126 |
$ git commit -m "..." |
1002 | 127 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
128 |
Commit all changed and previously manages files:: |
1002 | 129 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
130 |
$ git commit -a -m "...." |
1002 | 131 |
|
2084 | 132 |
Managing branches |
133 |
================= |
|
134 |
||
135 |
Print current branch:: |
|
136 |
||
137 |
$ git branch |
|
138 |
||
139 |
List all known branches:: |
|
140 |
||
141 |
$ git branch -a |
|
142 |
||
143 |
List all known remote branches:: |
|
144 |
||
145 |
$ git branch -r |
|
146 |
||
147 |
List all remote branches (from all remotes):: |
|
148 |
||
149 |
$ git ls-remote |
|
150 |
||
151 |
List remote branches from ``$REMOTE`` remote:: |
|
152 |
||
153 |
$ git ls-remote --heads $REMOTE |
|
154 |
$ git remote show $REMOTE |
|
155 |
||
156 |
.. note:: |
|
157 |
||
158 |
Look to ``[remote "..."]`` in ``~/.git/config`` to find out names of possible |
|
159 |
remotes. Alternatively get list from:: |
|
160 |
||
161 |
$ git remote show |
|
162 |
||
163 |
Getting branches pointers from default (``origin``) remote:: |
|
164 |
||
165 |
$ git fetch |
|
166 |
||
167 |
Getting branches pointers from ``$REMOTE`` remote:: |
|
168 |
||
169 |
$ git fetch $REMOTE |
|
170 |
||
171 |
.. note:: |
|
172 |
||
173 |
Only curtain branches fetched by default:: |
|
174 |
||
175 |
[remote "origin"] |
|
176 |
url = ... |
|
177 |
fetch = +refs/heads/*:refs/remotes/origin/* |
|
178 |
||
179 |
Edit ``fetch`` value to change defaults. |
|
180 |
||
181 |
||
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
182 |
git analog of 'hg incoming' |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
183 |
=========================== |
1002 | 184 |
|
185 |
git does not directly support such feature. You can emulate it by:: |
|
186 |
||
187 |
$ git fetch |
|
188 |
$ git log master..origin/master # or just '..origin/master' |
|
189 |
||
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
190 |
By previous commands you grab changes from remote server! You can apply them by |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
191 |
``pull`` or ``merge`` or ``rebase`` command:: |
1002 | 192 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
193 |
$ git pull |
1002 | 194 |
$ git merge |
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
195 |
TODO |
1002 | 196 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
197 |
To detect if remote repository have new changes:: |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
198 |
|
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
199 |
$ git ls-remote |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
200 |
$ git ls-remote $upstream |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
201 |
|
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
202 |
git analog of 'hg outgoing' |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
203 |
=========================== |
1002 | 204 |
|
205 |
git does not directly support such feature. You can emulate it by:: |
|
206 |
||
207 |
$ git fetch |
|
208 |
$ git log origin/master..master # or just 'origin/master..' |
|
209 |
||
1650
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
210 |
git analog of 'hg glog'. |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
211 |
======================== |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
212 |
:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
213 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
214 |
$ git log --all --graph |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
215 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
216 |
Add alias:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
217 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
218 |
[alias] |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
219 |
glog = log --all --graph |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
220 |
|
1651
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
221 |
Git analog of 'hg rollback'. |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
222 |
============================ |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
223 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
224 |
To edit commit message of last commit:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
225 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
226 |
$ git commit --amend -m "$MSG" |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
227 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
228 |
To edit messages of old commits starting from ``$REV``:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
229 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
230 |
$ git rebase -i $REV |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
231 |
|
1771
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
232 |
Git analog of 'hg root'. |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
233 |
======================== |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
234 |
:: |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
235 |
|
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
236 |
$ git rev-parse --show-toplevel |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
237 |
|
1002 | 238 |
Debug git network operation. |
239 |
============================ |
|
240 |
||
241 |
Git uses libcurl for network operation:: |
|
242 |
||
243 |
$ export GIT_CURL_VERBOSE=1 |
|
244 |
$ git ... |
|
245 |
||
1076
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
246 |
Push new repo to remote. |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
247 |
======================== |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
248 |
:: |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
249 |
|
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
250 |
$ mkdir $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
251 |
$ cd $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
252 |
$ git init |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
253 |
$ git add . |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
254 |
$ git commit -m "Initial commit" |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
255 |
$ git remote add origin https://$USER:$PASS@$HOST/$REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
256 |
$ git push -u origin master |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
257 |
|
1641
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
258 |
Show heads in branch. |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
259 |
===================== |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
260 |
:: |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
261 |
|
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
262 |
$ git show-ref --heads -s |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
263 |
|
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
264 |
Search string in file |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
265 |
===================== |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
266 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
267 |
To search string in all or specific files or working copy:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
268 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
269 |
$ git grep $PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
270 |
$ git grep -i $PATT -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
271 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
272 |
To search in all history:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
273 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
274 |
$ git log -S$PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
275 |
$ git log -G$PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
276 |
$ git grep -i PATT $(git rev-list --all) -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
277 |
|
1089
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
278 |
Find most recent tag for revision. |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
279 |
================================== |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
280 |
:: |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
281 |
|
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
282 |
$ git describe $REV |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
283 |
|
1815
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
284 |
Many projects set tags on branches rather then mainline (for example JS/CSS |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
285 |
projects perform build and commit binary/minified files, which unnecessary for |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
286 |
mainline history). In this case review simplifiied history by:: |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
287 |
|
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
288 |
$ git log --graph --all --decorate --oneline --simplify-by-decoration |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
289 |
|
1714
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
290 |
List tags with dates. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
291 |
===================== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
292 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
293 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
294 |
$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
295 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
296 |
Update to date. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
297 |
=============== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
298 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
299 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
300 |
$ git checkout 'master@{1979-02-26}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
301 |
$ git checkout 'master@{1979-02-26 18:30:00}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
302 |
|
1002 | 303 |
Using git to work with SVN offline. |
304 |
=================================== |
|
305 |
||
306 |
Prepare SVN and git utilities:: |
|
307 |
||
308 |
$ sudo apt-get svn git-core git-svn |
|
309 |
||
310 |
Making SVN repo:: |
|
311 |
||
312 |
$ cd $HOME/tmp |
|
313 |
$ svnadmin create svn-repo |
|
314 |
$ svn co file://$HOME/tmp/svn-repo svn-devel |
|
315 |
$ cd svn-devel |
|
316 |
$ mkdir tags trunk branches |
|
317 |
$ svn add * |
|
318 |
A branches |
|
319 |
A tags |
|
320 |
A trunk |
|
321 |
$ cd trunk/ |
|
322 |
$ printf "all:\n echo XXX\n" >Makefile |
|
323 |
$ printf "int main() {return 0;}" >main.c |
|
324 |
$ svn add * |
|
325 |
$ cd .. |
|
326 |
$ svn st |
|
327 |
A trunk |
|
328 |
A trunk/main.c |
|
329 |
A trunk/Makefile |
|
330 |
A branches |
|
331 |
A tags |
|
332 |
$ svn ci -m init |
|
333 |
Adding branches |
|
334 |
Adding tags |
|
335 |
Adding trunk |
|
336 |
Adding trunk/Makefile |
|
337 |
Adding trunk/main.c |
|
338 |
Transmitting file data .. |
|
339 |
$ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
340 |
$ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
341 |
||
342 |
Moving SVN changset to git repo:: |
|
343 |
||
344 |
$ cd $HOME/tmp |
|
345 |
$ git svn init file://$HOME/tmp/svn git-repo |
|
346 |
$ ls -a |
|
347 |
. .. .git |
|
348 |
$ git svn fetch |
|
349 |
A trunk/main.c |
|
350 |
A trunk/Makefile |
|
351 |
W: +empty_dir: branches |
|
352 |
W: +empty_dir: tags |
|
353 |
r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
354 |
A tags/v0.0/main.c |
|
355 |
A tags/v0.0/Makefile |
|
356 |
r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
357 |
M trunk/Makefile |
|
358 |
r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
359 |
A branches/v0.1/main.c |
|
360 |
A branches/v0.1/Makefile |
|
361 |
r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
362 |
M trunk/Makefile |
|
363 |
r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
364 |
Checked out HEAD: |
|
365 |
file:///home/sasha/tmp/svn r5 |
|
366 |
||
367 |
or (in old git version):: |
|
368 |
||
369 |
$ git svn clone file://$HOME/tmp/svn git-repo |
|
370 |
||
371 |
Making changes in svn:: |
|
372 |
||
373 |
$ cd $HOME/tmp/svn-devel/trunk |
|
374 |
$ echo ".PHONY: clean" >>Makefile |
|
375 |
$ svn ci -m "Added clean to phony." |
|
376 |
Sending trunk/Makefile |
|
377 |
Transmitting file data . |
|
378 |
Committed revision 6. |
|
379 |
||
380 |
Making committed in git:: |
|
381 |
||
382 |
$ cd $HOME/tmp/git-repo/trunk |
|
383 |
$ echo ".PHONY: all" >>Makefile |
|
384 |
$ echo "int foo(int x) {return x+x;}" >>main.c |
|
385 |
$ git status |
|
386 |
# On branch master |
|
387 |
# Changed but not updated: |
|
388 |
# (use "git add <file>..." to update what will be committed) |
|
389 |
# |
|
390 |
# modified: Makefile |
|
391 |
# modified: main.c |
|
392 |
# |
|
393 |
no changes added to commit (use "git add" and/or "git commit -a") |
|
394 |
$ git commit -a -m "Bug fixed." |
|
395 |
Created commit 222d399: Bug fixed. |
|
396 |
2 files changed, 2 insertions(+), 0 deletions(-) |
|
397 |
||
398 |
Getting changes from SVN to git:: |
|
399 |
||
400 |
$ git svn rebase |
|
401 |
M trunk/Makefile |
|
402 |
r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
|
403 |
First, rewinding head to replay your work on top of it... |
|
404 |
Applying Bug fixed. |
|
405 |
error: patch failed: trunk/Makefile:6 |
|
406 |
error: trunk/Makefile: patch does not apply |
|
407 |
Using index info to reconstruct a base tree... |
|
408 |
Falling back to patching base and 3-way merge... |
|
409 |
Auto-merged trunk/Makefile |
|
410 |
CONFLICT (content): Merge conflict in trunk/Makefile |
|
411 |
Failed to merge in the changes. |
|
412 |
Patch failed at 0001. |
|
413 |
||
414 |
When you have resolved this problem run "git rebase --continue". |
|
415 |
If you would prefer to skip this patch, instead run "git rebase --skip". |
|
416 |
To restore the original branch and stop rebasing run "git rebase --abort". |
|
417 |
||
418 |
rebase refs/remotes/git-svn: command returned error: 1 |
|
419 |
$ git add Makefile |
|
420 |
$ git rebase --continue |
|
421 |
Applying Bug fixed. |
|
422 |
||
423 |
and return all from git to SVN:: |
|
424 |
||
425 |
$ git svn dcommit |
|
426 |
Committing to file:///home/sasha/tmp/svn ... |
|
427 |
M trunk/Makefile |
|
428 |
M trunk/main.c |
|
429 |
Committed r7 |
|
430 |
M trunk/main.c |
|
431 |
M trunk/Makefile |
|
432 |
r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
433 |
No changes between current HEAD and refs/remotes/git-svn |
|
434 |
Resetting to the latest refs/remotes/git-svn |
|
435 |
||
436 |
See what going to SVN repo:: |
|
437 |
||
438 |
$ cd $HOME/tmp/svn-devel/trunk |
|
439 |
$ svn diff -r BASE:HEAD |
|
440 |
Index: Makefile |
|
441 |
=================================================================== |
|
442 |
--- Makefile (working copy) |
|
443 |
+++ Makefile (revision 7) |
|
444 |
@@ -6,4 +6,4 @@ |
|
445 |
.o: .c |
|
446 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
447 |
||
448 |
-.PHONY: clean |
|
449 |
+.PHONY: all clean |
|
450 |
Index: main.c |
|
451 |
=================================================================== |
|
452 |
--- main.c (working copy) |
|
453 |
+++ main.c (revision 7) |
|
454 |
@@ -2,3 +2,4 @@ |
|
455 |
{ |
|
456 |
return 0; |
|
457 |
} |
|
458 |
+int foo(int x) {return x+x;} |
|
459 |
$ svn up |
|
460 |
U Makefile |
|
461 |
U main.c |
|
462 |
Updated to revision 7. |
|
463 |
||
464 |
gitk. |
|
465 |
===== |
|
466 |
||
467 |
gitk - The git repository browser. See gitk(1). |
|
468 |
||
469 |
Installing:: |
|
470 |
||
471 |
$ sudo apt-get instal gitk |
|
472 |
||
473 |
Using:: |
|
474 |
||
475 |
$ cd /path/to/git-repo |
|
476 |
$ gitk |
|
477 |