git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git [2026/06/15 01:57] – [log] jhagstrand | git [2026/08/06 07:54] (current) – [repository] jhagstrand | ||
|---|---|---|---|
| Line 52: | Line 52: | ||
| === bare=== | === bare=== | ||
| a bare repository is a folder named project.git\\ | a bare repository is a folder named project.git\\ | ||
| - | a non-bare repository is a subfolder | + | a non-bare repository is a sub-folder |
| - | git init | + | git init # executed from within a new project folder, creates the .git folder |
| - | git clone | + | git init --bare flash.git |
| + | | ||
| + | git clone < | ||
| ====remote==== | ====remote==== | ||
| Line 268: | Line 270: | ||
| | git checkout < | | git checkout < | ||
| - | The old checkout | + | The old checkout |
| + | |||
| + | **git checkout < | ||
| + | This allows developers to work on multiple ideas at once, and switch back and forth. | ||
| + | |||
| + | **git checkout < | ||
| + | When you change your mind about the changes you've made, restore the file back to where it was before you started. | ||
| + | |||
| + | **git checkout < | ||
| + | When I'm testing my app and I'm not sure if my latest commit was successful, | ||
| + | I can temporarily switch back to the previous commit and test that to refresh my memory. | ||
| + | |||
| + | Note that this results in a " | ||
| + | The HEAD is a pointer to a commit. | ||
| + | Anytime the HEAD is pointed at a commit other than the one at the top of the current branch, it is considered detached. | ||
| + | Repeat the git checkout < | ||
| + | |||
| + | ==== checkout ==== | ||
| + | |||
| + | The repo is a library of commits. | ||
| + | At any time, you can checkout a whole commit or a specific file within that commit. | ||
| + | |||
| + | A branch is a pointer | ||
| + | The HEAD is also a pointer to a commit. | ||
| + | |||
| + | When the HEAD points to a commit that is not also the top of a branch, the HEAD is considered " | ||
| + | |||
| + | The checkout command does two things: | ||
| + | 1. Points the HEAD to the specified commit. | ||
| + | 2. Brings the working tree into line with the new HEAD commit. | ||
| + | |||
| + | You can specify a commit, a branch, or a file. | ||
| + | |||
| + | | ||
| + | git checkout < | ||
| + | git checkout < | ||
| + | |||
| + | You can specify a branch or a commit; either way you are specifying a commit. | ||
| + | If you specify a file, there is no need to move the HEAD. It just modifies that one file in the working tree to bring it into line with the current commit. | ||
| + | |||
| + | Younger | ||
| + | |||
| + | ^ correct | ||
| + | | git checkout < | ||
| + | | git checkout < | ||
| + | |||
| + | |||
| + | |||
| + | |||
| - | (Note that checkout of a commit is extraordinary and results in a detached HEAD.) | ||
| ====diff==== | ====diff==== | ||
| - | Use diff to find the differences between two branches or between two files.\\ | + | Use diff to find the differences between two commits.\\ |
| - | Note that there is a big difference between .. and ... between the two commit designations.\\ | + | |
| - | Also the two hyphens -- can go before or after the filename and that alters the output.\\ | + | |
| - | git diff master...featurebranch | + | |
| - | | + | |
| - | git diff 1bde095..b0ba90d -- html/js/hud.js | + | git diff master sidebar |
| By default diff compares all of the currently modified files. | By default diff compares all of the currently modified files. | ||
| - | git diff | + | git diff |
| - | git add . | + | git add . # staging |
| - | git diff HEAD # after the add | + | git diff HEAD # after staging |
| + | git diff --staged | ||
| Additional options. | Additional options. | ||
| + | git diff master sidebar --stat | ||
| git diff -U0 # do not display context | git diff -U0 # do not display context | ||
| - | | ||
| - | git diff -w # ignore whitespace | ||
| - | git diff -w --word-diff-regex=[^[: | ||
| + | Whitespace.\\ | ||
| In .gitconfig, add | In .gitconfig, add | ||
| [core] whitespace = -trailing-space, | [core] whitespace = -trailing-space, | ||
| + | git diff -w # ignore whitespace | ||
| + | git diff -w --word-diff-regex=[^[: | ||
| + | |||
| + | Dots.\\ | ||
| + | If both master and sidebar have changed, and you want to see only differences in sidebar, use three dots. (This is a shortcut to naming the commit specifically.)\\ | ||
| + | Warning! Two dots vs three dots makes a difference, and the difference is reversed in git diff vs git log.\\ | ||
| + | |||
| + | git diff master sidebar poker.js | ||
| + | git diff master..sidebar poker.js | ||
| + | git diff master...sidebar poker.js | ||
| + | |||
| + | Double hyphens.\\ | ||
| + | I don't know why this is used.\\ | ||
| + | |||
| + | git diff master sidebar hud.js | ||
| + | git diff master sidebar -- hud.js | ||
| + | git diff master sidebar hud.js -- | ||
| ====log==== | ====log==== | ||
| Line 305: | Line 370: | ||
| git log --all --oneline --graph --decorate | git log --all --oneline --graph --decorate | ||
| git log --oneline -10 # topmost n lines | git log --oneline -10 # topmost n lines | ||
| + | git log --all --pretty=fuller | ||
| ==== interactive rebase ==== | ==== interactive rebase ==== | ||
| Line 321: | Line 386: | ||
| https:// | https:// | ||
| + | |||
| + | ==== Combinations ==== | ||
| + | |||
| + | Some git command options effectively execute multiple git commands simultaneously. | ||
| + | Here are some examples. | ||
| + | |||
| + | 1. git add . | ||
| + | 2. git commit -m ' | ||
| + | 1+2. git -a commit -m ' | ||
| + | |||
| + | 1. git clone < | ||
| + | 2. git submodule init | ||
| + | 3. git submodule update | ||
| + | 2+3. git submodule update --init | ||
| + | 1+2+3. git clone --recursive-submodules < | ||
| + | |||
| + | 1. git fetch # download patch files | ||
| + | 2. git merge # apply patches to local files | ||
| + | 1+2. git pull # fetch and merge | ||
| + | |||
| + | ====Fork==== | ||
| + | In github ui, fork repo from voyc to hagstrand. | ||
| + | |||
| + | Locally: | ||
| + | git clone xttps:// | ||
| + | git remote add upstream xttps: | ||
| + | git pull --rebase upstream master | ||
| + | # pull does a fetch and merge into local directory. | ||
| + | git push origin master | ||
| + | Todo: Rename? | ||
| + | Todo: In github UI, “Pull Request” to bring forked project back into upstream. | ||
| + | |||
| + | |||
| ===== How to use ===== | ===== How to use ===== | ||
| Line 602: | Line 700: | ||
| git submodule update --init | git submodule update --init | ||
| - | ==== Combinations ==== | ||
| - | Some git command options effectively execute multiple git commands simultaneously. | ||
| - | Here are some examples. | ||
| - | 1. git add . | + | ==== Remove |
| - | 2. git commit -m ' | + | |
| - | 1+2. git -a commit -m ' | + | |
| - | 1. git clone <project> | + | Remove a submodule but keep the working tree. |
| - | 2. git submodule | + | <code> |
| - | 3. git submodule update | + | # 1. Remove the submodule |
| - | | + | git submodule |
| - | 1+2+3. git clone --recursive-submodules < | + | |
| - | 1. git fetch # download patch files | + | # 2. Remove it from git's index and the .git/ |
| - | | + | git rm -f path/to/submodule |
| - | 1+2. git pull # fetch and merge | + | rm -rf .git/ |
| - | ====Fork==== | + | # 3. Commit the removal |
| - | In github ui, fork repo from voyc to hagstrand. | + | git commit |
| - | + | ||
| - | Locally: | + | |
| - | git clone xttps:// | + | |
| - | git remote add upstream xttps: | + | |
| - | git pull --rebase upstream master | + | |
| - | # pull does a fetch and merge into local directory. | + | |
| - | git push origin master | + | |
| - | Todo: Rename? | + | |
| - | Todo: In github UI, “Pull Request” to bring forked project back into upstream. | + | |
| - | ====See | + | # 4. Re-add |
| - | git diff # before staging (git add *) | + | git add path/ |
| - | git diff --staged # after staging | + | git commit |
| + | </ | ||
| =====Alternative Workflows===== | =====Alternative Workflows===== | ||
git.1781503061.txt.gz · Last modified: 2026/06/15 01:57 by jhagstrand