git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git [2026/06/14 02:08] – [merge vs rebase] jhagstrand | git [2026/06/16 00:13] (current) – [diff] jhagstrand | ||
|---|---|---|---|
| Line 29: | Line 29: | ||
| * HEAD - ? | * HEAD - ? | ||
| * detached head - ? | * detached head - ? | ||
| + | * tree-ish ? | ||
| * commit-ish | * commit-ish | ||
| * SHA-1 value | * SHA-1 value | ||
| Line 205: | Line 206: | ||
| + | Starting situation\\ | ||
| + | There are commits on the feature branch.\\ | ||
| + | What about the master branch? | ||
| + | * no commits on the master | ||
| + | * commits on the master but no conflicts | ||
| + | * commits on the master with conflicts | ||
| + | Desired outcome.\\ | ||
| + | The master branch is up-to-date, and the feature branch is gone.\\ | ||
| + | But how will the log look? There are three possibilities: | ||
| + | * Linear. The feature branch commits are all present in the master branch, as if the branch never existed. | ||
| + | * Indented. The feature branch commits have are all present, but indented under a merge commit, so you can see there must have been a branch there at one time. | ||
| + | * Collapsed. The feature branch commits are all gone, replaced by a single merge commit with a hand-written merge message that summarizes all the commits of the branch. | ||
| + | |||
| + | ==== Squash Merge ==== | ||
| + | |||
| + | The --squash option, the merge command does not really do a merge. | ||
| + | |||
| + | This is one of the ways to collapse a developer' | ||
| + | |||
| + | # Make sure you're on the branch you want to merge into | ||
| + | git checkout master | ||
| + | | ||
| + | # merge the feature branch with --squash option | ||
| + | # this stages all the file changes into the master branch | ||
| + | git merge --squash feature | ||
| + | | ||
| + | # ask for status now and you'll see all the changes ready for commit | ||
| + | git status | ||
| + | | ||
| + | # now commit | ||
| + | git commit -m "feat: add feature command" | ||
| + | | ||
| + | # delete the feature branch | ||
| + | git branch -D feature | ||
| + | | ||
| + | # for fun do a log all between these commands to see what's going on | ||
| + | git log --all --oneline -15 --graph --decorate | ||
| + | |||
| + | ==== Log ==== | ||
| + | |||
| + | git commit adds an entry to the log. | ||
| + | |||
| + | How to fuck with the log. | ||
| + | |||
| + | * git merge | ||
| + | * git rebase | ||
| + | * git reset | ||
| + | |||
| + | git reset --hard HEAD^ | ||
| + | Effectively deletes the most recent commit. | ||
| Line 222: | Line 273: | ||
| ====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. | ||
| Line 238: | Line 287: | ||
| 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=[^[: | ||
| - | ====log==== | + | 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 log | + | |
| + | git diff master..sidebar poker.js | ||
| + | git diff master...sidebar poker.js | ||
| - | git log --oneline -10 | + | Double hyphens.\\ |
| + | I don't know why this is used.\\ | ||
| - | git log --oneline | + | |
| + | git diff master sidebar | ||
| + | git diff master sidebar hud.js | ||
| + | |||
| + | ====log==== | ||
| + | git log | ||
| + | git log master | ||
| + | git log --oneline -10 # default to currently checked out branch | ||
| + | git log --all --oneline --graph --decorate | ||
| + | git log --oneline -10 # topmost n lines | ||
| + | git log --all --pretty=fuller | ||
| ==== interactive rebase ==== | ==== interactive rebase ==== | ||
git.1781417308.txt.gz · Last modified: 2026/06/14 02:08 by jhagstrand