User Tools

Site Tools


git_cheat_sheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git_cheat_sheet [2022/12/01 02:59] – [Try Git] stephengit_cheat_sheet [2026/08/07 05:01] (current) stephen
Line 18: Line 18:
  
 <code text> <code text>
-[core] 
- editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession 
- pager = cat 
- 
 [user] [user]
  name = Stephen Heise  name = Stephen Heise
Line 28: Line 24:
 [init] [init]
  defaultBranch = main  defaultBranch = main
- 
-[mergetool] 
- prompt = false 
- keepBackup = false 
- keepTemporaries = false 
- 
-[merge] 
- tool = winmerge 
- 
-[mergetool "winmerge"] 
- name = WinMerge 
- trustExitCode = true 
- cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e -dl \"Local\" -dr \"Remote\" $LOCAL $REMOTE $MERGED 
- 
-[diff] 
- tool = winmerge 
- 
-[difftool "winmerge"] 
- name = WinMerge 
- trustExitCode = true 
- cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE 
  
 [push] [push]
Line 54: Line 29:
  autoSetupRemote = true  autoSetupRemote = true
    
 +[remote "origin"]
 + prune = true
 +
 [alias] [alias]
  st = status  st = status
  ci = commit -m  ci = commit -m
  ca = commit --amend --no-edit  ca = commit --amend --no-edit
 + cu = reset HEAD~
 + cuh = reset --hard HEAD~
  br = branch  br = branch
  ba = branch -a  ba = branch -a
Line 65: Line 45:
  fa = fetch -a  fa = fetch -a
  tf = !git reset && git checkout -- . && git clean -df  tf = !git reset && git checkout -- . && git clean -df
 + as = !git add . && git stash
 + pr = !git stash pop && git reset
  brdr = push --delete origin  brdr = push --delete origin
  fp = push --force  fp = push --force
Line 72: Line 54:
  ro2mfp = !git ro2m && echo 'Force pushing' && git fp  ro2mfp = !git ro2m && echo 'Force pushing' && git fp
  
-[winUpdater+# Linux only 
- recentlySeenVersion 2.15.1.windows.2+[credential
 + helper = /usr/local/bin/git-credential-manager 
 + credentialStore secretservice
  
-[remote "origin"] +[credential "https://dev.azure.com"] 
- prune = true+ useHttpPath = true 
 + 
 +# Windows only 
 +[core] 
 + editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession 
 + pager = cat 
 + longpaths = true 
 + 
 +[mergetool] 
 + prompt = false 
 + keepBackup = false 
 + keepTemporaries = false 
 + 
 +[merge] 
 + tool = winmerge 
 + 
 +[mergetool "winmerge"
 + name = WinMerge 
 + trustExitCode = true 
 + cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e -dl \"Local\" -dr \"Remote\" $LOCAL $REMOTE $MERGED 
 + 
 +[diff] 
 + tool = winmerge 
 + 
 +[difftool "winmerge"
 + name = WinMerge 
 + trustExitCode = true 
 + cmd = "/c/Program\\ Files\\ \\(x86\\)/WinMerge/WinMergeU.exe" -u -e $LOCAL $REMOTE
 </code> </code>
  
Line 97: Line 108:
  
 ''<nowiki>git config --list --show-origin</nowiki>'' ''<nowiki>git config --list --show-origin</nowiki>''
 +
 +===== Install on Linux =====
 +
 +  - Install Git Credential Manager
 +    - ''<nowiki>sudo apt-get update</nowiki>''
 +    - ''<nowiki>sudo apt-get install git-credential-manager</nowiki>''
 +    - Or download from [[https://github.com/git-ecosystem/git-credential-manager/releases]], assets, gcm-linux-x64-2.x.x.deb.
 +  - Configure Git to use Git Credential Manager
 +    - ''<nowiki>git config --global credential.helper manager</nowiki>''
 +  - Select the credential store backend
 +    - ''<nowiki>git config --global credential.credentialStore secretservice</nowiki>''
 +  - Verify GNOME Keyring (Secret Service) is running
 +    - Run: ''<nowiki>ps aux | grep keyring</nowiki>'', look for ''<nowiki>gnome-keyring-daemon</nowiki>''.
 +    - If missing, start it with: ''<nowiki>gnome-keyring-daemon --start --components=secrets</nowiki>''
 +
  
 ===== Try Git ===== ===== Try Git =====
Line 137: Line 163:
 | ''<nowiki>git push --force origin HEAD~10:$(git rev-parse --abbrev-ref HEAD)</nowiki>'' | Force push up to the last 10 commits. | | ''<nowiki>git push --force origin HEAD~10:$(git rev-parse --abbrev-ref HEAD)</nowiki>'' | Force push up to the last 10 commits. |
 | ''<nowiki>gitk</nowiki>'' | A commit viewer. | | ''<nowiki>gitk</nowiki>'' | A commit viewer. |
-| ''<nowiki>gitk 'stash@{0}'</nowiki>'' | View the contents of the first stash. | 
 | ''<nowiki>gitk --all $(git fsck --no-reflog | Select-String "(dangling commit )(.*)" | %{ $_.Line.Split(' ')[2] })</nowiki>'' | Find a dropped stash. | | ''<nowiki>gitk --all $(git fsck --no-reflog | Select-String "(dangling commit )(.*)" | %{ $_.Line.Split(' ')[2] })</nowiki>'' | Find a dropped stash. |
 | ''<nowiki>git tag -a <tagname> -m "commit comment"</nowiki>'' | Annotated tag (preferred over lightweight tags). | | ''<nowiki>git tag -a <tagname> -m "commit comment"</nowiki>'' | Annotated tag (preferred over lightweight tags). |
Line 144: Line 169:
 | ''<nowiki>git log --no-merges --oneline develop..</nowiki>'' | Show all commits on the current branch. | | ''<nowiki>git log --no-merges --oneline develop..</nowiki>'' | Show all commits on the current branch. |
 | ''<nowiki>git cherry-pick ebe6942^..905e279</nowiki>'' | Cherry-pick an //inclusive// commit range. | | ''<nowiki>git cherry-pick ebe6942^..905e279</nowiki>'' | Cherry-pick an //inclusive// commit range. |
 +| ''<nowiki>git --git-dir=../<other repo>/.git format-patch -k -1 --stdout <commit hash> | git am -3 -k</nowiki>'' | 'Cherry pick' a commit from another repo. |
 +| ''<nowiki>git remote -v</nowiki>'' | View remote / origin URL. |
 +|  Stashing  | |
 +| ''<nowiki>gitk 'stash@{0}'</nowiki>'' | View the contents of the first stash. |
 +| ''<nowiki>git diff stash</nowiki>'' | Shows differences between your current working tree and the most recent stash entry. |
 +| ''<nowiki>git diff stash@{0}</nowiki>'' | Shows differences against a specific stash entry (here, the latest one explicitly). |
 +| ''<nowiki>git diff --name-only stash</nowiki>'' | Lists only file names that differ between your working tree and the stash. |
 +| ''<nowiki>git diff stash -- path/to/file.cs</nowiki>'' | Shows differences against the stash for only the specified file. |
 +
 +
 +
  
 ===== Workflows ===== ===== Workflows =====
Line 267: Line 303:
 </code> </code>
  
 +===== Who needs to clean up =====
 +
 +Lists the author and date of the last commit on each remote branch.
 +
 +Bash:
 +<code bash>
 +for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t$branch; done | sort -r
 +</code>
 +
 +Powershell:
 +<code powershell>
 +git branch -r | Where-Object { $_ -notmatch 'HEAD' } | ForEach-Object {
 +    $branch = $_.Trim()
 +    $info = git show --format="%ai %ar by %an" $branch | Select-Object -First 1
 +    [PSCustomObject]@{
 +        Info = $info
 +        Branch = $branch
 +    }
 +} | Sort-Object Info -Descending | Format-Table -AutoSize
 +</code>
 ===== How PRs work ===== ===== How PRs work =====
  
git_cheat_sheet.1669863599.txt.gz · Last modified: 2022/12/02 04:00 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki