author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Mon, 23 Nov 2020 00:32:17 +0200 | |
changeset 2468 | cab0464c11f4 |
parent 2414 | aebcb023e71a |
child 2505 | 5262c08480dc |
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 |
|
2101 | 9 |
Setting up git |
10 |
============== |
|
1002 | 11 |
|
2101 | 12 |
Debian:: |
1002 | 13 |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
14 |
$ sudo apt-get install git |
1002 | 15 |
|
2101 | 16 |
Cygwin:: |
17 |
||
18 |
$ setup.exe -p git |
|
19 |
$ apt-cyg install git |
|
20 |
||
21 |
After install set up some options:: |
|
1002 | 22 |
|
23 |
$ git config --global user.name "Oleksandr Gavenko" |
|
24 |
$ git config --global user.mail "gavenkoa@gmail.com" |
|
2101 | 25 |
|
26 |
After that you should have:: |
|
27 |
||
1002 | 28 |
$ cat ~/.gitconfig |
29 |
[user] |
|
2101 | 30 |
name = Oleksandr Gavenko |
31 |
mail = gavenkoa@gmail.com |
|
1002 | 32 |
|
33 |
git over proxy. |
|
34 |
=============== |
|
35 |
||
36 |
Only http:// protocol support proxy (not git://):: |
|
37 |
||
38 |
$ export http_proxy="http://username:password@proxy:port/" |
|
39 |
$ git clone http://github.com/$user/$proj.git $proj |
|
40 |
||
41 |
You can store proxy settings under repository local config file:: |
|
42 |
||
43 |
$ git config http.proxy http://$user:$passwd@$ip:$port |
|
44 |
||
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
45 |
Start project with git |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
46 |
====================== |
1002 | 47 |
|
48 |
Setup proj space on fs:: |
|
49 |
||
50 |
$ mkdir proj |
|
51 |
$ cd proj |
|
52 |
$ git init |
|
53 |
Initialized empty Git repository in /home/user/tmp/proj/.git/ |
|
54 |
$ ls -a |
|
55 |
. .. .git |
|
56 |
||
57 |
Add file, make changes, commit all:: |
|
58 |
||
59 |
$ emacs Makefile |
|
60 |
... C-x C-c |
|
61 |
$ emacs app.c |
|
62 |
... C-x C-c |
|
63 |
$ git add Makefile app.c |
|
64 |
$ git status |
|
65 |
# On branch master |
|
66 |
# |
|
67 |
# Initial commit |
|
68 |
# |
|
69 |
# Changes to be committed: |
|
70 |
# (use "git rm --cached <file>..." to unstage) |
|
71 |
# |
|
72 |
# new file: Makefile |
|
73 |
# new file: app.c |
|
74 |
# |
|
75 |
||
76 |
or just:: |
|
77 |
||
78 |
$ git add . |
|
79 |
||
80 |
Commit newlly added file:: |
|
81 |
||
82 |
$ git commit |
|
83 |
... Write message log ... |
|
84 |
Created initial commit 2169263: My first commit massage. |
|
85 |
1 files changed, 4 insertions(+), 0 deletions(-) |
|
86 |
create mode 100644 app.c |
|
87 |
||
2209 | 88 |
Show difference |
89 |
=============== |
|
90 |
||
91 |
Show difference between index/stage and working tree:: |
|
92 |
||
93 |
$ git diff |
|
94 |
||
95 |
Show difference between ``HEAD`` and index (what is going to be commited):: |
|
96 |
||
97 |
$ git diff --cached |
|
98 |
$ git diff --staged |
|
99 |
||
100 |
.. note:: ``--cached`` and ``--staged`` are synonyms. |
|
101 |
||
102 |
Show difference beetween ``HEAD`` and working tree (what is commited after ``git commit -a``):: |
|
103 |
||
104 |
$ git diff HEAD |
|
105 |
$ git diff HEAD -- $path |
|
106 |
||
107 |
Show difference in changeset:: |
|
108 |
||
109 |
$ git show $hash |
|
110 |
||
111 |
Show difference between revisions:: |
|
112 |
||
113 |
$ git diff $rev1..$rev2 |
|
114 |
$ git diff ORIG_HEAD..HEAD |
|
115 |
||
2414
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
116 |
For merge first parent is a tip where merge is performed, second is a tip of merged branch. |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
117 |
|
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
118 |
.. note:: ``git show`` shows "combined diff": only files which were modified from all parents. |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
119 |
``git show --first-parent`` can be used to show how branch was chaged after merge. |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
120 |
|
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
121 |
Show differences to each parent for merge:: |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
122 |
|
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
123 |
$ git show -m $hash |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
124 |
|
2209 | 125 |
https://stackoverflow.com/questions/3293607/difference-between-git-head-and-the-current-project-state |
126 |
Difference between git HEAD and the current project state? |
|
2414
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
127 |
https://stackoverflow.com/questions/40986518/git-show-of-a-merge-commit |
aebcb023e71a
Show differences to each parent for merge.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2409
diff
changeset
|
128 |
git show of a merge commit. |
2209 | 129 |
|
1002 | 130 |
Undo tracking added file. |
131 |
========================= |
|
132 |
||
133 |
You do:: |
|
134 |
||
135 |
$ git add badfile |
|
136 |
$ git status |
|
137 |
# On branch master |
|
138 |
# Changes to be committed: |
|
139 |
# (use "git reset HEAD <file>..." to unstage) |
|
140 |
# |
|
141 |
# new file: badfile |
|
142 |
# |
|
143 |
||
144 |
To stop tracking badfile do:: |
|
145 |
||
146 |
$ git rm --cached badfile |
|
147 |
$ git status |
|
148 |
# On branch master |
|
149 |
# Untracked files: |
|
150 |
# (use "git add <file>..." to include in what will be committed) |
|
151 |
# |
|
152 |
# file |
|
153 |
nothing added to commit but untracked files present (use "git add" to track) |
|
154 |
||
155 |
or:: |
|
156 |
||
157 |
$ git reset badfile |
|
158 |
||
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
159 |
Committing changes |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
160 |
================== |
1002 | 161 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
162 |
Individual file:: |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
163 |
|
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
164 |
$ $EDITOR Makefile |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
165 |
$ git add Makefile |
2152
a48ba30d5b20
Fixed example for done changes review.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2126
diff
changeset
|
166 |
$ git diff --cached |
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
167 |
$ git commit -m "..." |
1002 | 168 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
169 |
Commit all changed and previously manages files:: |
1002 | 170 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
171 |
$ git commit -a -m "...." |
1002 | 172 |
|
2084 | 173 |
Managing branches |
174 |
================= |
|
175 |
||
176 |
Print current branch:: |
|
177 |
||
178 |
$ git branch |
|
179 |
||
180 |
List all known branches:: |
|
181 |
||
182 |
$ git branch -a |
|
183 |
||
184 |
List all known remote branches:: |
|
185 |
||
186 |
$ git branch -r |
|
187 |
||
2409
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
188 |
List all remote branches directly from remote:: |
2084 | 189 |
|
190 |
$ git ls-remote |
|
2190 | 191 |
$ git ls-remote origin |
192 |
||
193 |
List registered remotes:: |
|
194 |
||
2409
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
195 |
$ git remote -v |
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
196 |
$ git remote |
2190 | 197 |
$ git remote show |
2084 | 198 |
|
199 |
List remote branches from ``$REMOTE`` remote:: |
|
200 |
||
201 |
$ git ls-remote --heads $REMOTE |
|
202 |
$ git remote show $REMOTE |
|
203 |
||
2190 | 204 |
Special case of above is ``origin`` remote, which is default remote:: |
205 |
||
206 |
$ git remote show origin |
|
207 |
$ git ls-remote --heads origin |
|
208 |
||
2084 | 209 |
.. note:: |
210 |
||
211 |
Look to ``[remote "..."]`` in ``~/.git/config`` to find out names of possible |
|
212 |
remotes. Alternatively get list from:: |
|
213 |
||
214 |
$ git remote show |
|
215 |
||
2190 | 216 |
Getting branches pointers from default (``origin``) remote (without merging |
217 |
tracking branch):: |
|
2084 | 218 |
|
219 |
$ git fetch |
|
220 |
||
221 |
Getting branches pointers from ``$REMOTE`` remote:: |
|
222 |
||
223 |
$ git fetch $REMOTE |
|
224 |
||
2190 | 225 |
To get updated with default remote changes:: |
226 |
||
227 |
$ git pull |
|
228 |
||
229 |
or specify concrete remote:: |
|
230 |
||
231 |
$ git pull $REMOTE |
|
232 |
$ git pull origin |
|
233 |
||
2360
5179f42afc84
Delete remote branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2292
diff
changeset
|
234 |
Delete local branch (``-D`` is unsafe i.e. changes aren't pushed to any remote):: |
2214
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
235 |
|
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
236 |
$ git branch -d $NAME |
2360
5179f42afc84
Delete remote branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2292
diff
changeset
|
237 |
$ git branch -D $NAME |
2214
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
238 |
|
2253 | 239 |
Delete remote branch:: |
2214
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
240 |
|
2360
5179f42afc84
Delete remote branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2292
diff
changeset
|
241 |
$ git push $REMOTE --delete $BRANCH_NAME |
5179f42afc84
Delete remote branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2292
diff
changeset
|
242 |
$ git push $REMOTE -d $BRANCH_NAME |
5179f42afc84
Delete remote branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2292
diff
changeset
|
243 |
$ git push origin -d $BRANCH_NAME |
2214
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
244 |
|
2190 | 245 |
To locally remove pointers to deleted remotely branches:: |
246 |
||
247 |
$ git remote update --prune |
|
248 |
$ git remote update --prune origin |
|
249 |
||
2084 | 250 |
.. note:: |
251 |
||
252 |
Only curtain branches fetched by default:: |
|
253 |
||
254 |
[remote "origin"] |
|
2123
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
255 |
url = ... |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
256 |
fetch = +refs/heads/*:refs/remotes/origin/* |
2084 | 257 |
|
258 |
Edit ``fetch`` value to change defaults. |
|
259 |
||
2171
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
260 |
Move branch pointer to arbitrary hash:: |
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
261 |
|
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
262 |
$ git branch -f $NAME $HASH |
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
263 |
|
2409
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
264 |
Create local branch from remote with the same name:: |
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
265 |
|
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
266 |
$ git checkout --track origin/fix |
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
267 |
|
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
268 |
Create local branch from remote with an alternative name:: |
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
269 |
|
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
270 |
$ git checkout -b myfix origin/fix |
6163ed9ff6de
Create local branch from remote with the same name.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2403
diff
changeset
|
271 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
272 |
git analog of 'hg incoming' |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
273 |
=========================== |
1002 | 274 |
|
275 |
git does not directly support such feature. You can emulate it by:: |
|
276 |
||
277 |
$ git fetch |
|
278 |
$ git log master..origin/master # or just '..origin/master' |
|
279 |
||
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
280 |
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
|
281 |
``pull`` or ``merge`` or ``rebase`` command:: |
1002 | 282 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
283 |
$ git pull |
1002 | 284 |
$ git merge |
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
285 |
TODO |
1002 | 286 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
287 |
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
|
288 |
|
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
289 |
$ git ls-remote |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
290 |
$ git ls-remote $upstream |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
291 |
|
2126 | 292 |
View git commits |
293 |
================ |
|
294 |
||
295 |
Review specific commit with:: |
|
296 |
||
297 |
$ git show $REV |
|
298 |
$ git diff $REV^ $REV |
|
299 |
||
2292
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
300 |
Review merge commit related to specific parent:: |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
301 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
302 |
$ git diff $REV^1 $REV |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
303 |
$ git diff $REV^2 $REV |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
304 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
305 |
$ git diff HEAD^1 HEAD |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
306 |
$ git diff HEAD^2 HEAD |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
307 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
308 |
.. note:: ``^1`` is the first parent, ``^2`` is the second parent, and so on. |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
309 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
310 |
``git show`` command for merge commits shows only changes from conflicting hunks. It is equivalent |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
311 |
to (lines that changed as part of the conflict resolution):: |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
312 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
313 |
$ git diff-tree --cc $REV |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
314 |
|
2126 | 315 |
Review difference between commits:: |
316 |
||
317 |
$ git $REV1 $REV2 |
|
2153
e88e36e73ebc
Review difference between commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2152
diff
changeset
|
318 |
$ git $REV1..$REV2 |
e88e36e73ebc
Review difference between commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2152
diff
changeset
|
319 |
$ git $REV1..$REV2 -- $DIR_OR_FILE |
2126 | 320 |
|
321 |
Review history with diffs:: |
|
322 |
||
323 |
$ git log -p |
|
324 |
$ git log -p $FROM_REV |
|
325 |
||
2292
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
326 |
Review history of merges only:: |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
327 |
|
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
328 |
$ git log --min-parents=2 -p --cc |
cd4554e0150e
Review history of merges only.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2262
diff
changeset
|
329 |
|
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
330 |
View unpublished git commits / analog of git 'hg outgoing' |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
331 |
========================================================== |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
332 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
333 |
``git`` does not directly support such feature. Recently ``hg`` start tracking |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
334 |
changes that pushed to any other repositories (called as ``public`` versus |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
335 |
``draft`` which is not yet published anywhere). You can emulate it by:: |
1002 | 336 |
|
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
337 |
$ git fetch origin |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
338 |
$ git log origin/master..master |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
339 |
$ git log origin/master.. |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
340 |
$ git log origin/master..HEAD |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
341 |
$ git log @{u}.. |
1002 | 342 |
|
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
343 |
$ git diff origin/master.. |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
344 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
345 |
Verbose syntax:: |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
346 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
347 |
$ git log --branches --not --remotes |
1002 | 348 |
|
2123
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
349 |
http://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
350 |
Viewing unpushed Git commits. |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
351 |
http://stackoverflow.com/questions/3636914/how-can-i-see-what-i-am-about-to-push-with-git |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
352 |
How can I see what I am about to push with git? |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
353 |
|
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
354 |
git analog of 'hg glog' |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
355 |
======================= |
1650
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
356 |
:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
357 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
358 |
$ git log --all --graph |
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
359 |
$ git log --all --graph --oneline |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
360 |
$ git log --all --graph --oneline --decorate |
1650
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
361 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
362 |
Add alias:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
363 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
364 |
[alias] |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
365 |
glog = log --all --graph |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
366 |
|
2116 | 367 |
Git analog of 'hg rollback' |
368 |
=========================== |
|
1651
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
369 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
370 |
To edit commit message of last commit:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
371 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
372 |
$ git commit --amend -m "$MSG" |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
373 |
|
2116 | 374 |
To integrate changes into last commit (``-a`` to avoid antecedent ``git add ...``, |
375 |
``--no-edit`` if you don't like to change commit message, otherwise external |
|
376 |
editor is opened):: |
|
377 |
||
378 |
$ git commit -a --amend --no-edit |
|
379 |
||
1651
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
380 |
To edit messages of old commits starting from ``$REV``:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
381 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
382 |
$ git rebase -i $REV |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
383 |
|
2124 | 384 |
To undo latest commit:: |
385 |
||
386 |
$ git reset HEAD~1 |
|
387 |
||
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
388 |
Git analog of 'hg root' |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
389 |
======================= |
1771
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
390 |
:: |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
391 |
|
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
392 |
$ git rev-parse --show-toplevel |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
393 |
|
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
394 |
Making local branch tracking remote |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
395 |
=================================== |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
396 |
:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
397 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
398 |
$ git branch -u upstream/foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
399 |
$ git branch -u upstream/foo foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
400 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
401 |
$ git branch --set-upstream-to=upstream/foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
402 |
$ git branch --set-upstream-to=upstream/foo foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
403 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
404 |
Showing what and how local branches are tracked:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
405 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
406 |
$ git branch -vv |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
407 |
$ cat .git/gitconfig |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
408 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
409 |
Showing what remote branches tracked:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
410 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
411 |
$ git remote show $remote |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
412 |
|
2115
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
413 |
Undo mistaken rebase |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
414 |
==================== |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
415 |
|
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
416 |
If there are no any ``reset``, ``rebase`` or ``merge`` afterwards the easiest |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
417 |
way to recode to pre-rebase state is one of:: |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
418 |
|
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
419 |
$ git rebase --abort |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
420 |
$ git reset --hard ORIG_HEAD |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
421 |
|
2172
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
422 |
Otherwise look to:: |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
423 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
424 |
$ git reflog |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
425 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
426 |
and reset to necessary head:: |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
427 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
428 |
$ git reset --hard "HEAD@{...}" |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
429 |
|
2173
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
430 |
https://stackoverflow.com/questions/134882/undoing-a-git-rebase |
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
431 |
Undoing git rebase. |
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
432 |
|
2179 | 433 |
Undo reset --hard |
434 |
================= |
|
435 |
||
436 |
``git reset --hard`` is destructive command without backup data. |
|
437 |
||
438 |
You may find your previously added data in Git garbage:: |
|
439 |
||
440 |
$ git fsck --lost-found |
|
441 |
||
442 |
look to files inside ``.git/lost-found`` directory. |
|
443 |
||
444 |
Reviewing ``git reflog`` also may help. |
|
445 |
||
446 |
* https://stackoverflow.com/questions/5788037/recover-from-git-reset-hard |
|
447 |
* https://stackoverflow.com/questions/14251194/how-to-recover-after-i-execute-git-reset-hard-head |
|
448 |
||
2232
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
449 |
Undo mistaken push |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
450 |
================== |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
451 |
:: |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
452 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
453 |
$ git reset HEAD^ |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
454 |
$ git push --force |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
455 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
456 |
Alternative commands may look like:: |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
457 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
458 |
$ git reset --hard $HASH |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
459 |
$ git push -u origin master --force |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
460 |
|
2233
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
461 |
You can delete remote branch with syntax of appended colon before branch name:: |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
462 |
|
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
463 |
$ git reset HEAD^ |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
464 |
$ git push origin :$NAME |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
465 |
$ git push origin $NAME |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
466 |
|
2175 | 467 |
Git bisect |
468 |
========== |
|
469 |
||
2176 | 470 |
``bad`` changes should be later in graph history then ``good`` ones. To use |
471 |
alternative names:: |
|
472 |
||
473 |
$ git start --term-old=... --term-new=... |
|
2175 | 474 |
|
475 |
Start bisecting with:: |
|
476 |
||
477 |
$ git bisect start |
|
478 |
||
479 |
Mark good and bad revisions:: |
|
480 |
||
481 |
$ git co vBAD |
|
482 |
$ make test |
|
483 |
$ git bisect bad |
|
484 |
||
485 |
$ git co vGOOD |
|
486 |
$ make test |
|
487 |
$ git bisect good |
|
488 |
||
489 |
||
490 |
If build/test failed to complete use:: |
|
491 |
||
492 |
$ git bisect skip |
|
493 |
||
494 |
To restore mistakenly marked revisions:: |
|
495 |
||
496 |
$ git bisect log >$LOG |
|
497 |
$ git bisect reset |
|
498 |
$ $EDITOR $LOG |
|
499 |
$ git bisect replay $LOG |
|
500 |
||
2211 | 501 |
Import patch |
502 |
============ |
|
503 |
||
504 |
Check patch summary:: |
|
505 |
||
506 |
git apply --stat my.patch |
|
507 |
||
508 |
Detect possible errors during patch application:: |
|
509 |
||
510 |
git apply --check my.patch |
|
511 |
||
512 |
Apply patch to working tree without commit:: |
|
513 |
||
514 |
git apply my.patch |
|
515 |
||
516 |
Commit patch:: |
|
517 |
||
518 |
git am my.patch |
|
519 |
||
520 |
Commit patch by signing you as reviewer:: |
|
521 |
||
522 |
git am --signoff my.patch |
|
523 |
||
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
524 |
Debug git network operation |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
525 |
=========================== |
1002 | 526 |
|
527 |
Git uses libcurl for network operation:: |
|
528 |
||
529 |
$ export GIT_CURL_VERBOSE=1 |
|
530 |
$ git ... |
|
531 |
||
1076
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
532 |
Push new repo to remote. |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
533 |
======================== |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
534 |
:: |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
535 |
|
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
536 |
$ mkdir $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
537 |
$ cd $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
538 |
$ git init |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
539 |
$ git add . |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
540 |
$ git commit -m "Initial commit" |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
541 |
$ git remote add origin https://$USER:$PASS@$HOST/$REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
542 |
$ git push -u origin master |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
543 |
|
1641
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
544 |
Show heads in branch. |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
545 |
===================== |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
546 |
:: |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
547 |
|
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
548 |
$ git show-ref --heads -s |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
549 |
|
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
550 |
Search string in file |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
551 |
===================== |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
552 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
553 |
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
|
554 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
555 |
$ git grep $PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
556 |
$ git grep -i $PATT -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
557 |
|
2403
f5347f511cb3
To search for string in commit messages.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2402
diff
changeset
|
558 |
To search for string in commit messages:: |
f5347f511cb3
To search for string in commit messages.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2402
diff
changeset
|
559 |
|
f5347f511cb3
To search for string in commit messages.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2402
diff
changeset
|
560 |
$ git log --grep $PATT |
f5347f511cb3
To search for string in commit messages.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2402
diff
changeset
|
561 |
$ git log --grep $PATT --all |
f5347f511cb3
To search for string in commit messages.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2402
diff
changeset
|
562 |
|
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
563 |
To search in all history:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
564 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
565 |
$ git log -S$PATT |
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
566 |
$ git log --pickaxe-regex=$PATT |
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
567 |
$ git log -G$PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
568 |
$ git grep -i PATT $(git rev-list --all) -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
569 |
|
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
570 |
.. note:: |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
571 |
|
2402 | 572 |
``-G`` search occurences in diff chunks, while ``-S`` detects changes in match count. |
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
573 |
|
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
574 |
https://git-scm.com/book/en/v2/Git-Tools-Searching |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
575 |
Git Tools - Searching. |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
576 |
https://stackoverflow.com/questions/1337320/how-to-grep-git-commit-diffs-or-contents-for-a-certain-word |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
577 |
How to grep Git commit diffs or contents for a certain word? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
578 |
https://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
579 |
Search all of Git history for a string? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
580 |
https://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
581 |
How to grep (search) committed code in the git history? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
582 |
|
1089
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
583 |
Find most recent tag for revision. |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
584 |
================================== |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
585 |
:: |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
586 |
|
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
587 |
$ git describe $REV |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
588 |
|
1815
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
589 |
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
|
590 |
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
|
591 |
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
|
592 |
|
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
593 |
$ 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
|
594 |
|
1714
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
595 |
List tags with dates. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
596 |
===================== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
597 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
598 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
599 |
$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
600 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
601 |
Update to date. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
602 |
=============== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
603 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
604 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
605 |
$ git checkout 'master@{1979-02-26}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
606 |
$ git checkout 'master@{1979-02-26 18:30:00}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
607 |
|
1002 | 608 |
Using git to work with SVN offline. |
609 |
=================================== |
|
610 |
||
611 |
Prepare SVN and git utilities:: |
|
612 |
||
613 |
$ sudo apt-get svn git-core git-svn |
|
614 |
||
615 |
Making SVN repo:: |
|
616 |
||
2251 | 617 |
$ cd $HOME/tmp |
618 |
$ svnadmin create svn-repo |
|
619 |
$ svn co file://$HOME/tmp/svn-repo svn-devel |
|
620 |
||
621 |
$ cd svn-devel |
|
622 |
$ mkdir tags trunk branches |
|
623 |
||
624 |
$ svn add * |
|
1002 | 625 |
A branches |
626 |
A tags |
|
627 |
A trunk |
|
2251 | 628 |
|
629 |
$ cd trunk/ |
|
630 |
$ printf "all:\n echo XXX\n" >Makefile |
|
631 |
$ printf "int main() {return 0;}" >main.c |
|
632 |
||
633 |
$ svn add * |
|
634 |
||
635 |
$ cd .. |
|
636 |
||
637 |
$ svn st |
|
1002 | 638 |
A trunk |
639 |
A trunk/main.c |
|
640 |
A trunk/Makefile |
|
641 |
A branches |
|
642 |
A tags |
|
2251 | 643 |
|
644 |
$ svn ci -m init |
|
1002 | 645 |
Adding branches |
646 |
Adding tags |
|
647 |
Adding trunk |
|
648 |
Adding trunk/Makefile |
|
649 |
Adding trunk/main.c |
|
650 |
Transmitting file data .. |
|
651 |
$ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
652 |
$ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
653 |
||
654 |
Moving SVN changset to git repo:: |
|
655 |
||
2251 | 656 |
$ cd $HOME/tmp |
657 |
$ git svn init file://$HOME/tmp/svn git-repo |
|
658 |
$ ls -a |
|
1002 | 659 |
. .. .git |
2251 | 660 |
|
661 |
$ git svn fetch |
|
1002 | 662 |
A trunk/main.c |
663 |
A trunk/Makefile |
|
664 |
W: +empty_dir: branches |
|
665 |
W: +empty_dir: tags |
|
666 |
r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
667 |
A tags/v0.0/main.c |
|
668 |
A tags/v0.0/Makefile |
|
669 |
r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
670 |
M trunk/Makefile |
|
671 |
r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
672 |
A branches/v0.1/main.c |
|
673 |
A branches/v0.1/Makefile |
|
674 |
r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
675 |
M trunk/Makefile |
|
676 |
r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
677 |
Checked out HEAD: |
|
678 |
file:///home/sasha/tmp/svn r5 |
|
679 |
||
680 |
or (in old git version):: |
|
681 |
||
682 |
$ git svn clone file://$HOME/tmp/svn git-repo |
|
683 |
||
684 |
Making changes in svn:: |
|
685 |
||
2251 | 686 |
$ cd $HOME/tmp/svn-devel/trunk |
687 |
$ echo ".PHONY: clean" >>Makefile |
|
688 |
$ svn ci -m "Added clean to phony." |
|
1002 | 689 |
Sending trunk/Makefile |
690 |
Transmitting file data . |
|
691 |
Committed revision 6. |
|
692 |
||
693 |
Making committed in git:: |
|
694 |
||
2251 | 695 |
$ cd $HOME/tmp/git-repo/trunk |
696 |
$ echo ".PHONY: all" >>Makefile |
|
697 |
$ echo "int foo(int x) {return x+x;}" >>main.c |
|
698 |
$ git status |
|
1002 | 699 |
# On branch master |
700 |
# Changed but not updated: |
|
701 |
# (use "git add <file>..." to update what will be committed) |
|
702 |
# |
|
703 |
# modified: Makefile |
|
704 |
# modified: main.c |
|
705 |
# |
|
706 |
no changes added to commit (use "git add" and/or "git commit -a") |
|
707 |
$ git commit -a -m "Bug fixed." |
|
708 |
Created commit 222d399: Bug fixed. |
|
709 |
2 files changed, 2 insertions(+), 0 deletions(-) |
|
710 |
||
711 |
Getting changes from SVN to git:: |
|
712 |
||
2251 | 713 |
$ git svn rebase |
714 |
M trunk/Makefile |
|
1002 | 715 |
r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
716 |
First, rewinding head to replay your work on top of it... |
|
717 |
Applying Bug fixed. |
|
718 |
error: patch failed: trunk/Makefile:6 |
|
719 |
error: trunk/Makefile: patch does not apply |
|
720 |
Using index info to reconstruct a base tree... |
|
721 |
Falling back to patching base and 3-way merge... |
|
722 |
Auto-merged trunk/Makefile |
|
723 |
CONFLICT (content): Merge conflict in trunk/Makefile |
|
724 |
Failed to merge in the changes. |
|
725 |
Patch failed at 0001. |
|
726 |
||
727 |
When you have resolved this problem run "git rebase --continue". |
|
728 |
If you would prefer to skip this patch, instead run "git rebase --skip". |
|
729 |
To restore the original branch and stop rebasing run "git rebase --abort". |
|
730 |
||
731 |
rebase refs/remotes/git-svn: command returned error: 1 |
|
732 |
$ git add Makefile |
|
733 |
$ git rebase --continue |
|
734 |
Applying Bug fixed. |
|
735 |
||
736 |
and return all from git to SVN:: |
|
737 |
||
2251 | 738 |
$ git svn dcommit |
1002 | 739 |
Committing to file:///home/sasha/tmp/svn ... |
740 |
M trunk/Makefile |
|
741 |
M trunk/main.c |
|
742 |
Committed r7 |
|
743 |
M trunk/main.c |
|
744 |
M trunk/Makefile |
|
745 |
r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
746 |
No changes between current HEAD and refs/remotes/git-svn |
|
747 |
Resetting to the latest refs/remotes/git-svn |
|
748 |
||
749 |
See what going to SVN repo:: |
|
750 |
||
2251 | 751 |
$ cd $HOME/tmp/svn-devel/trunk |
752 |
$ svn diff -r BASE:HEAD |
|
1002 | 753 |
Index: Makefile |
754 |
=================================================================== |
|
755 |
--- Makefile (working copy) |
|
756 |
+++ Makefile (revision 7) |
|
757 |
@@ -6,4 +6,4 @@ |
|
758 |
.o: .c |
|
759 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
760 |
||
761 |
-.PHONY: clean |
|
762 |
+.PHONY: all clean |
|
763 |
Index: main.c |
|
764 |
=================================================================== |
|
765 |
--- main.c (working copy) |
|
766 |
+++ main.c (revision 7) |
|
767 |
@@ -2,3 +2,4 @@ |
|
768 |
{ |
|
769 |
return 0; |
|
770 |
} |
|
771 |
+int foo(int x) {return x+x;} |
|
772 |
$ svn up |
|
773 |
U Makefile |
|
774 |
U main.c |
|
775 |
Updated to revision 7. |
|
776 |
||
2262
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
777 |
Get latest changes from SVN and update Git repo state:: |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
778 |
|
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
779 |
$ git svn fetch |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
780 |
$ git svn rebase |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
781 |
|
1002 | 782 |
gitk. |
783 |
===== |
|
784 |
||
785 |
gitk - The git repository browser. See gitk(1). |
|
786 |
||
787 |
Installing:: |
|
788 |
||
789 |
$ sudo apt-get instal gitk |
|
790 |
||
791 |
Using:: |
|
792 |
||
793 |
$ cd /path/to/git-repo |
|
794 |
$ gitk |
|
795 |