git
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
git [2018/05/09 15:51] – [Multiple Repos] thekojukinator | git [2019/05/08 16:08] (current) – [PowerShell Visual Studio Code Template] thekojukinator | ||
---|---|---|---|
Line 7: | Line 7: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
I was using '' | I was using '' | ||
Line 16: | Line 17: | ||
For further configuration options, see the [[https:// | For further configuration options, see the [[https:// | ||
- | === Set name and e-mail address | + | ==== Contact Info for Commits ==== |
<code bash> | <code bash> | ||
Line 23: | Line 24: | ||
</ | </ | ||
- | === Set handling of line endings | + | ==== Handling Line Endings ==== |
<code bash> | <code bash> | ||
Line 34: | Line 35: | ||
</ | </ | ||
- | === Set alias for pretty log output | + | A complementary setting in //Visual Studio Code// when developing on Windows is to enforce CRLF. |
+ | |||
+ | <code css settings.json> | ||
+ | { | ||
+ | // this assumes Windows dev environment with Git config option " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | ==== Pretty Log Alias ==== | ||
More helpful aliases are demonstrated [[https:// | More helpful aliases are demonstrated [[https:// | ||
This log command will give nice and pretty output: | This log command will give nice and pretty output: | ||
+ | |||
<code bash> | <code bash> | ||
git log --pretty=format:" | git log --pretty=format:" | ||
+ | # or without pagination | ||
+ | git --no-pager log --pretty=format:" | ||
</ | </ | ||
It can be configured in to a global alias like so: | It can be configured in to a global alias like so: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global alias.hist "log --pretty=format:' | git config --global alias.hist "log --pretty=format:' | ||
+ | # unfortunately these won't work... | ||
+ | git config --global alias.hist " | ||
+ | git config --global alias.hist "!git --no-pager log --pretty=format:' | ||
+ | # but, this will disable pagination for all calls to ' | ||
+ | git config --global pager.log false | ||
+ | |||
+ | # I've recently discovered some prettier log outputs, so my .gitconfig aliases are like so... | ||
+ | hist = log --graph --abbrev-commit --decorate --format=format:' | ||
+ | hist1 = log --graph --abbrev-commit --decorate --format=format:' | ||
+ | hist2 = log --pretty=format:' | ||
+ | # first two are courtesy of https:// | ||
</ | </ | ||
So now it's simply enough to do: | So now it's simply enough to do: | ||
+ | |||
<code bash> | <code bash> | ||
git hist | git hist | ||
Line 55: | Line 80: | ||
</ | </ | ||
- | === Visual Studio Code as Git editor | + | ==== VSCode |
More info [[https:// | More info [[https:// | ||
Set //Visual Studio Code// as the default //Git// editor, and configure it to wait for the editor to close before continuing: | Set //Visual Studio Code// as the default //Git// editor, and configure it to wait for the editor to close before continuing: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global core.editor "code --wait" | git config --global core.editor "code --wait" | ||
Line 65: | Line 91: | ||
Now it's possible to edit the //Git// config in //Visual Studio Code// like so: | Now it's possible to edit the //Git// config in //Visual Studio Code// like so: | ||
+ | |||
<code bash> | <code bash> | ||
git config --global -e | git config --global -e | ||
Line 70: | Line 97: | ||
Leveraging the above, add the following to '' | Leveraging the above, add the following to '' | ||
+ | |||
< | < | ||
[diff] | [diff] | ||
Line 83: | Line 111: | ||
git config -l | git config -l | ||
# show global settings only | # show global settings only | ||
+ | # these live in the user profile | ||
git config --global -l | git config --global -l | ||
# show system settings only | # show system settings only | ||
+ | # these live in the git installation path | ||
git config --system -l | git config --system -l | ||
- | # show repo settings only (must be in repo folder) | + | # show local settings only |
+ | # these live in the repo | ||
git config --local -l | git config --local -l | ||
</ | </ | ||
Line 95: | Line 126: | ||
Create a **repo** in the current folder: | Create a **repo** in the current folder: | ||
+ | |||
<code bash> | <code bash> | ||
git init | git init | ||
Line 100: | Line 132: | ||
Create a **repo** in the folder '' | Create a **repo** in the folder '' | ||
+ | |||
<code bash> | <code bash> | ||
git init MyRepo | git init MyRepo | ||
Line 105: | Line 138: | ||
From the parent folder, it's possible to clone a **repo** with: | From the parent folder, it's possible to clone a **repo** with: | ||
+ | |||
<code bash> | <code bash> | ||
git clone < | git clone < | ||
Line 113: | Line 147: | ||
NOTE: A cloned **repo** will have a single '' | NOTE: A cloned **repo** will have a single '' | ||
- | === Bare Repos === | + | ==== Bare Repos ==== |
Doing '' | Doing '' | ||
Line 130: | Line 164: | ||
===== Multiple Repos ===== | ===== Multiple Repos ===== | ||
- | === Syncing === | + | ==== Syncing |
Commits are pulled down from a remote **repo** via '' | Commits are pulled down from a remote **repo** via '' | ||
Line 142: | Line 176: | ||
However, [[# | However, [[# | ||
+ | |||
<code bash> | <code bash> | ||
git merge origin/ | git merge origin/ | ||
Line 166: | Line 201: | ||
If, as mentioned in [[#managing remote repos]], local **branches** are already configured to track remote **branches**, | If, as mentioned in [[#managing remote repos]], local **branches** are already configured to track remote **branches**, | ||
- | === Tracking Branches === | + | ==== Tracking Branches |
When a **repo** is cloned, the only local **branch** is '' | When a **repo** is cloned, the only local **branch** is '' | ||
Line 180: | Line 215: | ||
It is possible to create a local **branch** that tracks commits from a remote **branch**: | It is possible to create a local **branch** that tracks commits from a remote **branch**: | ||
+ | |||
<code bash> | <code bash> | ||
# create a new localbranch to track remotebranch | # create a new localbranch to track remotebranch | ||
Line 188: | Line 224: | ||
It is also possible to modify an existing local **branch** and set it to track commits from a remote **branch**: | It is also possible to modify an existing local **branch** and set it to track commits from a remote **branch**: | ||
+ | |||
<code bash> | <code bash> | ||
# for currently checked out branch | # for currently checked out branch | ||
Line 206: | Line 243: | ||
</ | </ | ||
- | === Managing Remote Repos === | + | ==== Managing Remote Repos ==== |
<code bash> | <code bash> | ||
Line 263: | Line 300: | ||
git remote set-branches --add origin dev1 | git remote set-branches --add origin dev1 | ||
</ | </ | ||
+ | |||
+ | When a tag is removed from the local **repo** it will not be removed from the remote **repo** via standard '' | ||
+ | |||
+ | <code bash> | ||
+ | # delete <tag> from < | ||
+ | git push < | ||
+ | # ex: | ||
+ | git push origin :v1.0 | ||
+ | </ | ||
+ | |||
+ | Alternatively, | ||
===== Stage, Confirm, Commit, and Tag ===== | ===== Stage, Confirm, Commit, and Tag ===== | ||
Line 269: | Line 317: | ||
Stage files: | Stage files: | ||
+ | |||
<code bash> | <code bash> | ||
# a single file | # a single file | ||
Line 283: | Line 332: | ||
Confirm **repo** status: | Confirm **repo** status: | ||
+ | |||
<code bash> | <code bash> | ||
git status | git status | ||
Line 288: | Line 338: | ||
Commit changes: | Commit changes: | ||
+ | |||
<code bash> | <code bash> | ||
# commit and launch default editor to provide comment | # commit and launch default editor to provide comment | ||
Line 299: | Line 350: | ||
* Stage the necessary files | * Stage the necessary files | ||
* Perform a new commit with the '' | * Perform a new commit with the '' | ||
+ | |||
<code bash> | <code bash> | ||
git commit --amend -m " | git commit --amend -m " | ||
Line 304: | Line 356: | ||
Tag commits for easier management: | Tag commits for easier management: | ||
+ | |||
<code bash> | <code bash> | ||
# tag the current commit with a friendly name | # tag the current commit with a friendly name | ||
Line 329: | Line 382: | ||
This is not an undo, but instead of checking out files, it's possible to checkout a commit via the first 7 digits of the hash (from '' | This is not an undo, but instead of checking out files, it's possible to checkout a commit via the first 7 digits of the hash (from '' | ||
+ | |||
<code bash> | <code bash> | ||
git checkout < | git checkout < | ||
Line 336: | Line 390: | ||
To return to the latest commit do: | To return to the latest commit do: | ||
+ | |||
<code bash> | <code bash> | ||
git checkout < | git checkout < | ||
Line 343: | Line 398: | ||
Staged changes can be rolled back via '' | Staged changes can be rolled back via '' | ||
+ | |||
<code bash> | <code bash> | ||
# unstage all currently staged changes | # unstage all currently staged changes | ||
Line 353: | Line 409: | ||
NOTE: The working directory still has modified and unstaged files, use '' | NOTE: The working directory still has modified and unstaged files, use '' | ||
+ | |||
<code bash> | <code bash> | ||
git checkout . | git checkout . | ||
Line 362: | Line 419: | ||
This will cancel wherever '' | This will cancel wherever '' | ||
+ | |||
<code bash> | <code bash> | ||
git revert HEAD | git revert HEAD | ||
Line 369: | Line 427: | ||
To revert the working directory to a specified commit, and remove all later commits from history: | To revert the working directory to a specified commit, and remove all later commits from history: | ||
+ | |||
<code bash> | <code bash> | ||
git reset --hard < | git reset --hard < | ||
Line 376: | Line 435: | ||
NOTE: If removed commits had tags, those tags need to be removed or the commits will remain in history. This can be done after '' | NOTE: If removed commits had tags, those tags need to be removed or the commits will remain in history. This can be done after '' | ||
+ | |||
<code bash> | <code bash> | ||
git tag -d BadVersion | git tag -d BadVersion | ||
Line 412: | Line 472: | ||
Branches are managed via '' | Branches are managed via '' | ||
- | === Create, List, Checkout, and Delete === | + | ==== Create, List, Checkout, and Delete |
<code bash> | <code bash> | ||
Line 433: | Line 493: | ||
</ | </ | ||
- | === Merging === | + | ==== Merging |
<code bash> | <code bash> | ||
Line 443: | Line 503: | ||
</ | </ | ||
- | === Rebasing === | + | ==== Rebasing |
Branches can be rebased with '' | Branches can be rebased with '' | ||
Line 456: | Line 516: | ||
NOTE: Rebasing can get tricky in some scenarios and cause issues, check the documentation for further details: | NOTE: Rebasing can get tricky in some scenarios and cause issues, check the documentation for further details: | ||
+ | |||
<code bash> | <code bash> | ||
git rebase --help | git rebase --help | ||
Line 486: | Line 547: | ||
</ | </ | ||
- | === PowerShell Visual Studio Code Template === | + | ==== PowerShell Visual Studio Code Template |
This is my baseline template for starting a // | This is my baseline template for starting a // | ||
Line 497: | Line 558: | ||
!*/ | !*/ | ||
- | # allow .gitignore | + | # allow .git* at top level |
- | !.gitignore | + | !.git* |
- | # whitelist these file types everywhere | + | # allow .md at top level |
- | !**/*.ps1 | + | !*.md |
- | !**/*.psm1 | + | |
- | !**/*.psd1 | + | # whitelist VSCode settings at the top level |
- | !**/*.xml | + | !/.vscode/ |
+ | |||
+ | # whitelist contents of these folders at the top level | ||
+ | !/ | ||
+ | |||
+ | # regardless of above, ignore these folders and files everywhere | ||
+ | **/_logs* | ||
+ | **/_testing* | ||
- | # regardless of above, ignore ' | ||
- | **\.vscode/ | ||
</ | </ | ||
git.1525895503.txt.gz · Last modified: 2018/05/09 15:51 by thekojukinator