-
Notifications
You must be signed in to change notification settings - Fork 3
/
git
196 lines (138 loc) · 5.75 KB
/
git
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
# git http proxy
git config --global http.proxy http://xxx:[email protected]:3128
# To set your identify:
git config --global user.name "John Doe"
git config --global user.email [email protected]
# To set your editor:
git config --global core.editor emacs
# To enable color:
git config --global color.ui true
# To stage all changes for commit:
git add --all
# To commit staged changes
git commit -m "Your commit message"
# To edit previous commit message
git commit --amend
# To removed staged and working directory changes
git reset --hard
# To remove untracked files
git clean -f -d
# To remove untracked and ignored files
git clean -f -d -x
# To push to the tracked master branch:
git push origin master
# To push to a specified repository:
git push [email protected]:username/project.git
# To delete the branch "branch_name"
git branch -D branch_name
# To see who commited which line in a file
git blame filename
# To sync a fork with the master repo:
git remote add upstream [email protected]:name/repo.git # Set a new repo
git remote -v # Confirm new remote repo
git fetch upstream # Get branches
git branch -va # List local - remote branches
git checkout master # Checkout local master branch
git checkout -b new_branch # Create and checkout a new branch
git merge upstream/master # Merge remote into local repo
git show 83fb499 # Show what a commit did.
git show 83fb499:path/fo/file.ext # Shows the file as it appeared at 83fb499.
git diff branch_1 branch_2 # Check difference between branches
git log # Show all the commits
git status # Show the changes from last commit
# git export
git archive master | tar -x -C /somewhere/else
# git tar.gz
git archive master | bzip2 >source-tree.tar.bz2
# git ZIP archive:
git archive --format zip --output /full/path/to/zipfile.zip master
# find a commit in which branch
git name-rev 97374dab58cffa8a7d81881377b386dc42c0dcba
# show all refs, gerrit use refs/change/xxx save change
git show-ref
# delete refs
git update-ref -d refs/notes/origin/commits
# delete all branch and tag,expect master in remote
git ls-remote caf | awk '{ print $2 }' | sed '/^HEAD$/d' | sed '/master$/d' | xargs -n 20 git push caf --delete --
# delete all branch tag or other refs, expect master in local
git show-ref | awk '{ print $2 }' | sed '/^HEAD$/d' | sed '/master$/d' | xargs -n 1 git update-ref -d --
# fetch all gerrit changes in local, so that we can diff easy,and cherry-pick easy
git ls-remote origin | grep /changes/ | awk '{print $2;}' | while read REF
do
git fetch "${REMOTE}" "${REF}"
git branch ${echo "${REF}" | sed 's#refs/changes/../#change/#'} FETCH_HEAD
done
## how to find a file's sha1
git rev-parse HEAD:filename
## how to show a file's content by file sha1
git cat-file -p sha1
## show file tree
git cat-file -p HEAD^{tree}
## git hash file
$ echo 'test content' | git hash-object -w --stdin
d670460b4b4aece5915caf5c68d12f560a9fe3e4
# ls-remote
“Pull Request Refs” which we use to look at the raw references on the server.
# ls-files
“Manual File Re-merging”, “Rerere” and “The Index” to take a more raw look at what your staging area looks like.
# rev-parse
“Branch References” to take just about any string and turn it into an object SHA-1.
# write git script
. "$(git --exec-path)/git-sh-setup"
# list worktree
git worktree list
# add worktree
git worktree add yourpath your-branch
# skip https check
git config --global http.sslVerify false
# config git
<<<<<<< HEAD
HOME=/dev/null GIT_CONFIG_NOSYSTEM=1 git fetch --all
# show commit change with file list
git log --committer="xxx1.com" --committer="xxx2.com" --committer="xxx3.com" --committer="xxx4.com" --name-status
# set commit template
git config --global commit.template git-commit-template.txt
## push gerrit merged changes
for sha1 in $(git log --no-merges --author="@mail.com" --format="%H" | tac); do git push origin $sha1:refs/for/target_branch%merged; done
## git log to csv
### Local Dates:
git log --date=local --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.local.csv
### ISO Dates:
git log --date=iso --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.iso.scv
### use , to sperate
git log --pretty=format:%h,%an,%ae,%s > /path/to/file.csv
### get last month csv
git log --since="last month" --pretty=format:'%h,%an,%ar,%s' > log.csv
## remove remote
git remote rm sofake
## show all branches contains special commit
git branch -a --contains xxxxxxxxxxxxxxxxxx
## show ancestry path commit
git log <SHA1>..HEAD --ancestry-path --merges
## show the commit graph bu filter, verfy important for graph usage
git rev-list
## parse revision
git rev-parse xxx
## show gitconfig source
git config --list --show-origin
## merge with commit message
git merge $SHA1 --no-edit --no-stat --log=300 --no-ff -m "$COMMIT_MSG"
git commit --amend --no-edit
## allow fetch sha1
for each_project in $(find /home/git_mirror -name "*.git");do
cd "${each_project}"
git config uploadpack.allowReachableSHA1InWant true
done
# diff changes
git log --oneline --no-merges --pretty=format:"%H %an %cd %s" --date=format:'%Y/%m/%d' origin/xxx..origin/xxx > log_diff.txt
# use git save http password
git config --global credential.helper store
# git log with filechange
git log --name-status
# git log with changes
git log --stat
# config the ssh variant
git config --global ssh.variant ssh
HOME=/dev/null GIT_CONFIG_NOSYSTEM=1 git fetch --all
# commit format
git log --pretty=format:"%h %ce ----------------- %s"