User Tools

Site Tools


git

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 [2026/06/06 22:17] – [Diff] jhagstrandgit [2026/06/07 23:56] (current) – [Configuration] jhagstrand
Line 37: Line 37:
   * fourth: tags   * fourth: tags
   * refs:  branch, tag, remote   * refs:  branch, tag, remote
 +
 +Commands and things:
 +  * Execute the branch command to create a branch.
 +  * Execute the remote command to create a remote.
 +  * Execute the commit command to create a commit.
 +  * Execute the diff command to create a diff.
 +  * Execute the tag command to create a tag.
 +  * Exceptions: 
 +    * log, checkout, merge, push, pull are just commands.
 +    * repository and worktree are just things.
  
 ====repository==== ====repository====
Line 78: Line 88:
  
 ====commit==== ====commit====
-The "commit" is the unit of version control  + 
-Each commit is a version of the source code.+The commit command creates a commit. 
 + 
 +Each commit is a new version of the source code
 + 
 +Initial edits to a text file are tentative.  The commit command makes those edits permanent.
  
 Each commit is given a unique 20-character name by sha1. Each commit is given a unique 20-character name by sha1.
  
-To display the history of commits on project:+The chain of commits is a powerful debugging tool allowing programmers to review the history of changes to the code using the log and diff commands. 
 + 
 +  $ git log      # display a list of all the commits in reverse chronological order 
 +  $ git log --oneline -20 
 +  $ git diff     # compare the changes made between two commits  
 + 
 +The programmer composes commit message for each commit. 
 + 
 +  $ git commit -m 'Refactored the layermenu from table to flexbox.' 
 +  $ git commit   # skip the -m parameter and an editor will open to receive a multi-line message 
 + 
 +The multi-line commit message.   
 +  line 1 is title, max 50 chars 
 +  line 2 is blank, this is what signals git to split title and body 
 +  line 3+ is body, max 72 chars per line, hit enter to hardcode each newline 
 + 
 +The commit message title style guide. 
 +  * Like a document sub-heading 
 +  * Imperative 
 +  * Start with capital letter, no period at the end 
 +  * No articles or filler
  
-  $ git log 
-  $ git log --pretty=oneline 
  
 +The history log of commit messages, combined with skillful use of the branch, merge, reset, and rebase commands enable a programmer to communicate to future developers exactly what he changed and how, why and when.
  
 ====tag==== ====tag====
Line 102: Line 135:
   git show       # details of latest commit   git show       # details of latest commit
   git tag -d 1.0 # delete a tag   git tag -d 1.0 # delete a tag
 +
 +Tags are often used to implement public release versioning.  There are three common version formats.
 +
 +  * Marketing Versioning, like macOS Sonoma
 +
 +  * Calendar Versioning, like 2026.06.04
 +
 +  * Semantic Versioning (SemVer)
 +    * see https://semver.org/
 +    * major.minor.patch, like v3.6.2
 +    * minor and patch releases maintain backward compatibility
 +    * as soon as backward compatibility is broken, the major number must be incremented
 +    * important for a library with a public api, for example
 +
 +(I remember the good old days, when broken backward compatibility was a sign of incompetence.)
 +
 ====worktree==== ====worktree====
  
Line 144: Line 193:
 The checkout command has two different functions.  This can be confusing if you ever have a branch and a file with the same name.  In 2019 the switch and restore commands were introduced.  They eliminate the confusion and the command names are more self-explanatory. The checkout command has two different functions.  This can be confusing if you ever have a branch and a file with the same name.  In 2019 the switch and restore commands were introduced.  They eliminate the confusion and the command names are more self-explanatory.
  
-^ old                   ^ new                  ^ +^ old                    ^ new                  ^ 
-| git checkout <branch> | git switch <branch> +| git checkout <branch>  | git switch <branch> 
-| git checkout <file>   | git restore <file>   |+| git checkout <file>    | git restore <file>   | 
 +| git checkout <commit>  | (none)   |
  
 The old checkout commands still work as always.  And kudos to the git developers for honoring backward compatibility. The old checkout commands still work as always.  And kudos to the git developers for honoring backward compatibility.
  
 +(Note that checkout of a commit is extraordinary and results in a detached HEAD.)
 ====diff==== ====diff====
-git diff         # before the add git add . 
  
-git diff HEAD    # after the add +Use diff to find the differences between two branches or between two files.\\ 
-  +Note that there is a big difference between .. and ... between the two commit designations.\\ 
-git diff -U0 # do not display context+Also the two hyphens -- can go before or after the filename and that alters the output.\\
  
-git diff -w ignore whitespace+  git diff master...featurebranch  # compare two branches 
 +   
 +  git diff 1bde095..b0ba90d -html/js/hud.js  compare two different commits of a file
  
-git diff -w --word-diff-regex=[^[:space:]] # ignore whitespace additional+By default diff compares all of the currently modified files. 
 + 
 +  git diff         # before the add 
 +  git add . 
 +  git diff HEAD    # after the add 
 + 
 +Additional options. 
 + 
 +  git diff -U0 # do not display context 
 +   
 +  git diff -w # ignore whitespace 
 +  git diff -w --word-diff-regex=[^[:space:]] # ignore whitespace additional
  
 In .gitconfig, add  In .gitconfig, add 
 [core] whitespace = -trailing-space,-indent-with-non-tab,-tab-in-indent [core] whitespace = -trailing-space,-indent-with-non-tab,-tab-in-indent
 +
  
 ====log==== ====log====
Line 170: Line 234:
 git log --oneline -10 git log --oneline -10
  
-git log --oneline --graph +git log --oneline --graph # shows a hierarchy of branches
  
-git log --oneline --graph --decorate+==== interactive rebase ====
  
 +If you don't like the way the log looks now, the interactive rebase command lets you fix, reorder, drop and squash the commits, and reword the commit messages.  Do this in a branch you are working solo, not a public branch or one that has already been pushed.
  
 +  $ git switch mybranch
 +  $ git rebase -i HEAD~3
 +  $ git rebase -i b619fca0
 +
 +The log is displayed in reverse chronological order.
 +
 +The interactive rebase editor window displays the commits in chronological order.
 +
 +A note about reordering the commits.  The interactive rebase operation will start at the base and reapply your commits in new new order, rewriting your source code files in each commit.  It is possible to break code if you make a mistake.
 +
 +https://www.sitepoint.com/git-interactive-rebase-guide/
 ===== How to use ===== ===== How to use =====
  
 +
 +==== Configuration ====
 +
 +Use git config --global to set name and email.  
 +  * Support anonymity by using a shielded email, like for example the private GitLab noreply masked email.
 +  * Consider using a pair-programming persona as user.name to give credit to the AI author.
 +
 +  $ git config --global user.name "Your Name"
 +  $ git config --global user.name "Your Name & Gemini 1.5 Flash"  # pair-programming personna
 +  $ git config --global user.email "jerry@gmail.com"              # protect privacy on public host like gitlab
 +
 +Aider automatically adds a Co-authored by: line to the body.  Tell aider to skip that by adding parameters to .aider.conf.yml file:
 +  attribute-author: false
 +  attribute-committer: false
  
 ====Create a new repository==== ====Create a new repository====
git.1780798668.txt.gz · Last modified: 2026/06/06 22:17 by jhagstrand

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki