git_cheat_sheet
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git_cheat_sheet [2021/11/10 21:23] – stephen | git_cheat_sheet [2025/10/28 04:33] (current) – stephen | ||
|---|---|---|---|
| Line 21: | Line 21: | ||
| editor = ' | editor = ' | ||
| pager = cat | pager = cat | ||
| + | longpaths = true | ||
| [user] | [user] | ||
| name = Stephen Heise | name = Stephen Heise | ||
| email = Stephen@tallguyracing.com | email = Stephen@tallguyracing.com | ||
| + | |||
| + | [init] | ||
| + | defaultBranch = main | ||
| [mergetool] | [mergetool] | ||
| Line 49: | Line 53: | ||
| [push] | [push] | ||
| default = current | default = current | ||
| + | autoSetupRemote = true | ||
| + | |||
| [alias] | [alias] | ||
| st = status | st = status | ||
| ci = commit -m | ci = commit -m | ||
| - | ca = commit --amend | + | ca = commit --amend |
| br = branch | br = branch | ||
| ba = branch -a | ba = branch -a | ||
| Line 61: | Line 66: | ||
| 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 | ||
| cp = cherry-pick | cp = cherry-pick | ||
| ln = !git --no-pager log -n50 ' | ln = !git --no-pager log -n50 ' | ||
| + | ro2m = !echo ' | ||
| + | ro2mfp = !git ro2m && echo 'Force pushing' | ||
| [winUpdater] | [winUpdater] | ||
| Line 127: | Line 137: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| Line 135: | Line 147: | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| ===== Workflows ===== | ===== Workflows ===== | ||
| Line 211: | Line 225: | ||
| ==== Rebase onto master ==== | ==== Rebase onto master ==== | ||
| + | | ''< | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| | ''< | | ''< | ||
| + | |||
| + | ==== Split up an existing commit ==== | ||
| + | |||
| + | | ''< | ||
| + | | Mark commit to be split with ' | ||
| + | | Save & close | | | ||
| + | | When the rebasing has stopped... | | | ||
| + | | ''< | ||
| + | | Edit & commit. | | | ||
| + | | ''< | ||
| + | |||
| + | ==== Set up a bare repo ==== | ||
| + | |||
| + | | ''< | ||
| + | | ''< | ||
| + | | ''< | ||
| + | |||
| + | ==== Create a test repo ==== | ||
| + | |||
| + | <code powershell> | ||
| + | $scriptpath = Split-Path $MyInvocation.MyCommand.Path | ||
| + | Push-Location $scriptpath | ||
| + | |||
| + | $remoteRepoName = ' | ||
| + | $localRepoName = ' | ||
| + | |||
| + | mkdir $remoteRepoName | ||
| + | git init --bare $remoteRepoName | ||
| + | git clone $remoteRepoName $localRepoName | ||
| + | |||
| + | # Create an initial commit - optional | ||
| + | git --git-dir " | ||
| + | git --git-dir " | ||
| + | |||
| + | Pop-Location | ||
| + | </ | ||
| ===== Import from SVN ===== | ===== Import from SVN ===== | ||
| Line 220: | Line 271: | ||
| git svn clone https:// | git svn clone https:// | ||
| </ | </ | ||
| + | |||
| + | ===== Who needs to clean up ===== | ||
| + | |||
| + | Lists the author and date of the last commit on each remote branch. Need to run it on bash. | ||
| + | |||
| + | < | ||
| + | for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format=" | ||
| + | </ | ||
| + | |||
| + | ===== How PRs work ===== | ||
| + | |||
| + | When you create a PR on GitHub, it also creates some other refs for you. Different providers put these in different locations. | ||
| + | |||
| + | GitHub puts them under '' | ||
| + | |||
| + | If you run '' | ||
| + | |||
| + | On a GitHub repo with some active and completed pull requests, I see these ones (PR #2 has been closed, PR #1 is still open): | ||
| + | |||
| + | 5003f86523fa07e325d28f50a749685b93dffcf3 refs/ | ||
| + | 57c72505a9beed608fe73f474e77b70cd182616f refs/ | ||
| + | 622ba67a9d1279984dc763eb078d0e5d92ae790f refs/ | ||
| + | |||
| + | I believe that '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | Note that it’s a different commit hash to main '' | ||
| + | |||
| + | Now… to show when and how this changes I’ll need to create a new PR because there are conflicts on that example PR that I’m using. | ||
| + | |||
| + | As a side note: It seems as though these '' | ||
| + | |||
| + | Say we have a default branch '' | ||
| + | |||
| + | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | | ||
| + | Once I create a PR to merge '' | ||
| + | |||
| + | a94afcad87e765e18d590cc4090a835e210acca6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | 6b33d262276e1e5d520ffb8063dedffd6296664d refs/ | ||
| + | | ||
| + | Note '' | ||
| + | |||
| + | If I push changes to '' | ||
| + | |||
| + | 442fcf2d421c26f75339a82bd364d5fcc3bc0a52 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | e6317c4e97a465fe2f024e5a3cd5ff3f12c5f6a6 refs/ | ||
| + | 3a58fb072ff48e8bebf2c66491332556f3f935ef refs/ | ||
| + | |||
| + | '' | ||
| + | |||
| + | As for what these branches are used for: This is very useful for making sure that your code will still be valid after the merge is complete (not just in your branch). | ||
| + | If there are any changes to the source or target branches, '' | ||
| + | |||
git_cheat_sheet.1636579394.txt.gz · Last modified: 2021/11/11 22:23 (external edit)
