4,461
edits
→Signing work: add uploading of tags |
change syntaxhighlight to source |
||
Line 3: | Line 3: | ||
Get your GPG configured, and a personal key installed. Configure Git to use your personal key. | Get your GPG configured, and a personal key installed. Configure Git to use your personal key. | ||
< | <source lang="bash"> | ||
$ git config --global user.signingkey 0A46826A | $ git config --global user.signingkey 0A46826A | ||
</source> | </source> | ||
Line 36: | Line 11: | ||
You can sign commits simply by adding -S once your environment is configured. | You can sign commits simply by adding -S once your environment is configured. | ||
< | <source lang="bash"> | ||
$ git commit -S -m 'push a signed commit' | $ git commit -S -m 'push a signed commit' | ||
</ | </source> | ||
You can check and verify via <span class="package">git log</span>: | You can check and verify via <span class="package">git log</span>: | ||
< | <source lang="bash"> | ||
$ git log --show-signature -1 | $ git log --show-signature -1 | ||
</ | </source> | ||
You can configure <span class="package">git log</span> to check any signatures and list them in output via <span class="package">%G?</span> format. | You can configure <span class="package">git log</span> to check any signatures and list them in output via <span class="package">%G?</span> format. | ||
< | <source lang="bash"> | ||
$ git log --pretty="format:%h %G? %aN %s" | $ git log --pretty="format:%h %G? %aN %s" | ||
</ | </source> | ||
You can also reject commits that are unsigned and invalid: | You can also reject commits that are unsigned and invalid: | ||
< | <source lang="bash"> | ||
$ git merge --verify-signature non-verify | $ git merge --verify-signature non-verify | ||
$ git merge --verify-signatures signed-branch | $ git merge --verify-signatures signed-branch | ||
</ | </source> | ||
Sign the merge commit itself: | Sign the merge commit itself: | ||
< | <source lang="bash"> | ||
$ git merge --verify-signatures -S signed-branch | $ git merge --verify-signatures -S signed-branch | ||
</ | </source> | ||
= Commands = | = Commands = | ||
== Tags == | |||
Signing tags: | |||
<source lang="bash"> | |||
$ git tag -s v2.17 -m 'version 2.17 signed by MH' | |||
$ git show v2.17 | |||
</source> | |||
With the signer's public key in the keyring, you can verify the tag: | |||
<source lang="bash"> | |||
$ git tag -v v2.17 | |||
</source> | |||
Upload a specific tag: | |||
<source lang="bash"> | |||
$ git push origin v2.29.1 | |||
</source> | |||
Upload all tags: | |||
<source lang="bash"> | |||
$ git push origin --tags | |||
</source> | |||
== Get a build number == | == Get a build number == | ||
Line 72: | Line 74: | ||
A commit count can be used as a build number for a revision (e.g. HEAD, master, a commit hash): | A commit count can be used as a build number for a revision (e.g. HEAD, master, a commit hash): | ||
< | <source lang="bash"> | ||
$ git rev-list --count <revision> | $ git rev-list --count <revision> | ||
</ | </source> | ||
To get the commit count across all branches: | To get the commit count across all branches: | ||
< | <source lang="bash"> | ||
$ git rev-list --all --count | $ git rev-list --all --count | ||
</ | </source> | ||
== Add a local branch that tracks a remote branch == | == Add a local branch that tracks a remote branch == | ||
< | <source lang="bash"> | ||
$ git branch --track greet origin/greet | $ git branch --track greet origin/greet | ||
$ git branch -a | $ git branch -a | ||
$ git merge origin/master | $ git merge origin/master | ||
</ | </source> | ||
== Pulling changes from a remote == | == Pulling changes from a remote == | ||
Line 113: | Line 115: | ||
== Rebase a branch == | == Rebase a branch == | ||
< | <source lang="bash"> | ||
$ git checkout cbranch | $ git checkout cbranch | ||
Switched to branch 'cbranch' | Switched to branch 'cbranch' | ||
Line 124: | Line 126: | ||
$ | $ | ||
</ | </source> | ||
== Merge a branch == | == Merge a branch == | ||
< | <source lang="bash"> | ||
$ git checkout autonotif | $ git checkout autonotif | ||
Switched to branch 'autonotif' | Switched to branch 'autonotif' | ||
Line 137: | Line 139: | ||
1 file changed, 1 insertion(+) | 1 file changed, 1 insertion(+) | ||
create mode 100644 foobarrecords_savenew.hns | create mode 100644 foobarrecords_savenew.hns | ||
</ | </source> | ||
Merges <branchname> onto autonotif branch | Merges <branchname> onto autonotif branch | ||
Line 183: | Line 185: | ||
== Remove a tag == | == Remove a tag == | ||
< | <source lang="bash"> | ||
$ git tag -d <tagname> | $ git tag -d <tagname> | ||
</ | </source> | ||
== Undo last commit == | == Undo last commit == | ||
Line 191: | Line 193: | ||
This undo is recorded as a part of the git log. | This undo is recorded as a part of the git log. | ||
< | <source lang="bash"> | ||
$ git revert HEAD | $ git revert HEAD | ||
</ | </source> | ||
== Fix or amend last commit == | == Fix or amend last commit == | ||
Line 203: | Line 205: | ||
== Reset the branch to a specific point in the past == | == Reset the branch to a specific point in the past == | ||
< | <source lang="bash"> | ||
$ git reset --hard <hash> | $ git reset --hard <hash> | ||
</ | </source> | ||
--hard parameter also updates the working directory. Reset shouldn't be used in a group project on a remote repository because of its potential for confusion. | --hard parameter also updates the working directory. Reset shouldn't be used in a group project on a remote repository because of its potential for confusion. | ||
Line 213: | Line 215: | ||
;Temporary ignore changes to a file | ;Temporary ignore changes to a file | ||
< | <source lang="bash"> | ||
$ git update-index --assume-unchanged <filename> | $ git update-index --assume-unchanged <filename> | ||
</ | </source> | ||
;Back to tracking changes to the file | ;Back to tracking changes to the file | ||
< | <source lang="bash"> | ||
$ git update-index --no-assume-unchanged <filename> | $ git update-index --no-assume-unchanged <filename> | ||
</ | </source> | ||
;Get a list of folders and files that are <code>assume-unchanged</code> | ;Get a list of folders and files that are <code>assume-unchanged</code> | ||
< | <source lang="bash"> | ||
$ git ls-files -v | grep '^h' | $ git ls-files -v | grep '^h' | ||
</ | </source> | ||
== Ignore file modes == | == Ignore file modes == | ||
Line 241: | Line 243: | ||
Verify the connectivity and validity of the objects | Verify the connectivity and validity of the objects | ||
< | <source lang="bash"> | ||
$ git fsck --unreachable | $ git fsck --unreachable | ||
</ | </source> | ||
Manage reflog information | Manage reflog information | ||
< | <source lang="bash"> | ||
$ git reflog expire --expire=0 --all | $ git reflog expire --expire=0 --all | ||
</ | </source> | ||
Pack unpacked objects in a repository | Pack unpacked objects in a repository | ||
< | <source lang="bash"> | ||
$ git repack -a -d -l | $ git repack -a -d -l | ||
</ | </source> | ||
Prune all unreachable objects from the object database | Prune all unreachable objects from the object database | ||
< | <source lang="bash"> | ||
$ git prune | $ git prune | ||
</ | </source> | ||
Clean up unnecessary files and optimize the local repository | Clean up unnecessary files and optimize the local repository | ||
< | <source lang="bash"> | ||
$ git gc --aggressive | $ git gc --aggressive | ||
</ | </source> | ||
= Useful git aliases = | = Useful git aliases = | ||
Line 273: | Line 275: | ||
This is a snapshot of my ~/.gitconfig | This is a snapshot of my ~/.gitconfig | ||
< | <source lang="ini"> | ||
[user] | [user] | ||
name = Michael Han | name = Michael Han | ||
Line 305: | Line 307: | ||
[merge] | [merge] | ||
defaultToUpstream = true | defaultToUpstream = true | ||
</ | </source> | ||
= Links = | = Links = |