-
Notifications
You must be signed in to change notification settings - Fork 0
/
githelp.txt
274 lines (205 loc) · 7.38 KB
/
githelp.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
Don't let me Google that for you
Just ctrl-f this file
# The Git reference:
git checkout --help
# Configuring different personalities on one machine:
[user]
email = [email protected]
name = Hunor Kovacs
signingkey = 3DF729C6
[includeIf "gitdir:~/personal-workspace/"]
path = .gitconfig-personal
# Pushing
# Recommended pushing method
git push <remote> sourceBranch
git push origin master
# Push current branch to the same name. It's ok. Make sure you're there, where you think.
git push origin HEAD
# Explicit push.
git push <remote> sourceBranch:destinationBranch
# Push to origin all the branches that are tracked. Not recommended :)
git push
git push <remote>
# Deletes the toBeDeleted branch from origin.
git push origin :toBeDeleted
# Forces to update the pointers on the remote. Warning.
git push -f
# Pulling
git pull origin reposBranch:localBranch
git pull --rebase
# Pulls every tracked branch from every remote. Not recommended.
git pull
# Aliases. You may copy these into your .gitconfig
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
lg = log --decorate
gr = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
cl = clean -f -d .
rs = reset --hard HEAD
type = cat-file -t
dump = cat-file -p
poh = push origin HEAD
# Logging
git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
git log -SsomeStringYoureSearching --unified=3
git log origin/master..HEAD
git log b6b672a158c5 --unified=3 path/to/your/File.java
plus paramters: --pretty=oneline --max-count=2 --since='5 minutes ago' --until='5 minutes ago'
plus paramters: --author=Hun --all --decorate=full --not master --follow
# Displaying the contents of a commit
git show
git show <hash>
git show --format=fuller <hash>
git show --name-only
# Reverting
git revert 783hf2
git revert 1290fj --no-commit
git revert HEAD~4 --no-edit
# Revert a Git repository to a specific version, previous commit
git revert --no-commit 0766c053..HEAD
git commit
# To set your branch's tip to a specific commit (revert but reset-like)
git reset 56e05fced
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
git reset --hard
# Sharing
# Anywhere on the sharing computer>
git daemon --verbose --export-all --base-path="/home/kovacshuni/Code"
# Anywhere on the accessing compouter>
git ls-remote git://IP_orComputerName/Relative/path/to/dir/where/the/.git/is/based/on/the/base-path/on/remote
# Bundleing repo
git bundle create backup.bundle master
git bundle create backup.bundle master --all --tags --remotes
# Unbundle... unpack
git clone backup.bundle my-project
# Moving repositories
git clone --bare https://github.com/exampleuser/old-repository.git
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
# Ignoring files
# Long term ingore:
.gitignore file
# Short term ignore, updates
git update-index --assume-unchanged file1.txt file2.txt
git update-index --no-assume-unchanged file1.txt file2.txt
git-ls-files
git ls-files -v --others
# Long term ignore, locally only
.git/config/exclude file
# Diffs
# Changes in the working tree not yet staged for the next commit.
git diff
# diff staged files
git diff --cached
# Changes in the working tree since your last commit; what you would be committing if you run "git commit -a"
git diff HEAD
# Changes between two random revisions for a specific file.
git diff RELEASE-2.34..master -- path/to/file
# diff two random files
git diff HEAD:kubernetes/staging/a.deployment.yaml kubernetes/production/a.deployment.yaml
# Forcing a branch pointer to point to a commit. Do not use with shared objects.
git branch --force my-branch-name 7361f1fbh69
# Making a branch track a remote branch
git branch -u origin/master
# Rebasing
git rebase --interactive 69b79bb878fdae
git pull --rebase
o---o---o---o---o master
\
o---o---o---o---o next
\
o---o---o topic
git rebase --onto master next topic
o---o---o---o---o master
| \
| o'--o'--o' topic
\
o---o---o---o---o next
----------------------
# I have the following graph:
800 9ff
v v
----o--o--o--o--o--o <-master
\
o--o--o <-feature
# And i want the following state after the command:
800 9ff
v v
----o--o--o--o--o--o <-master
\
o--o--o <-feature
# So how do i rebase backwards on the same branch?
git rebase --onto 800 9ff
--------------------------
# Rebase first commit, to only have one
git rebase -i --root
# Editor to be Visual Studio Code
git config --global core.editor "code --wait"
# editor to be notepad++,
# Have notepad++ in your path. (Make sure you reopen all cmd windows.)
# go to your .gitconfig and add/edit
[core]
editor = notepad++.exe -multiInst -notabbar -nosession -noPlugin
# Blame
git blame -c config\mysql\staging\changes\2.12\492_insert_image_id_in_cc_image_format_mapping.sql
# Set up blame to skip formatting commits
echo "erf9e8f" > .git/config/.git-blame-ignore-revs
git config blame.ignoreRevsFile .git-blame-ignore-revs
https://stackoverflow.com/questions/53502654/how-do-i-run-a-code-formatter-over-my-source-without-modifying-git-history
# Cleaning unversioned files:
git clean -f -d
# Amending
git commit --amend --date="Wed 12 Jun 2012 09:18 +0000" --author="Your Name <[email protected]>"
git commit --amend --date="$(date -R)" ##in bash only
# Merging
# Merging fast forward only:
git merge --ff-only <branchname>
# Merging two branches without merging files.
# Merge discarding any changes B would introduce. Still, the commits from B are now in A. Files are at the state of A before the merge.
git merge -s ours B
# Recovering lost, detached commits:
git fsck --lost-found
# Showing diffs in stash:
git stash show -p stash@{0}
# Checking out (reverting to) a specific single file from a specific revision:
git checkout <hash> <path-to-file>
git checkout 8b8805a src/main/webapp/velocity/pageFragments/videoThumb.vm
# Patching
# First, commit the changes you want to patch.
git format-patch -1
git apply filename.patch
# Storing credentials on your machine. Uhh this is old, i'm not sure if you want to use this.
git config credential.helper store
git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[...several days later...]
git push http://example.com/repo.git
[your credentials are used automatically]
# Signing commits with your gpg key
git config --global user.signingkey F2C7AB29
git commit -S
# Always signing:
git config --global commit.gpgsign true
# Show tag on HEAD
git describe --tag —always
# Reset branch to no history / empty branch.
git update-ref -d HEAD
# Make empty commit
git commit --allow-empty -m "A new repo is born"
# Search code content in entire git database
git grep <regexp> $(git rev-list --all)
same:
git rev-list --all | xargs git grep <expression>
git grep <regexp> $(git rev-list --all -- lib/util) -- lib/util
https://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history
# Search history by commit message
git log --grep=<pattern>
# ignore changes to a file already indexed in your repository. careful when stashing, it might re-awaken it
git update-index --assume-unchanged chilipiper.code-workspace