User Tools

Site Tools


computing: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
computing:git [2026/04/26 10:38] – oscarcomputing:git [2026/10/01 10:42] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== GIT ====== 
  
----- 
-==== Getting Started ==== 
-^Task^Command^ 
-|Start a new repo|git init| 
-|Clone an existing repo|git clone <url>| 
-==== Configure Git ==== 
-^Task^Command^ 
-|Set a config option |git config user.name 'Your Name'| 
-|Set a config option |git config user.email 'Your email'| 
-|Set option globally |git config --global ... | 
-|Add an alias|git config alias.st status| 
-|See all possible config options| man git-config| 
- 
-==== Prepare to Commit ==== 
-^Task^Command^ 
-|Add untracked file or unstaged changes|git add <file>| 
-|Add all untracked files and unstaged changes|git add .| 
-|Choose which parts of a file to stage |git add -p| 
-|Move file|git mv <old> <new>| 
-|Delete file|git rm <file>| 
-|Tell Git to forget about a file without deleting it|git rm --cached <file>| 
-|Unstage one file|git reset <file>| 
-|Unstage everything|git reset| 
-|Check what you added|git status| 
- 
-==== Make Commits ==== 
-^Task^Command^ 
-|Make a commit (and open text editor to write message)|git commit| 
-|Make a commit|git commit -m 'message'| 
-|Commit all unstaged changes|git commit -am 'message'| 
- 
-==== Move Between Branches ==== 
-^Task^Command^ 
-|Switch branches|git switch <name> OR git checkout <name>| 
-|Create a branch|git switch -c <name> OR git checkout -b <name>| 
-|List branches|git branch| 
-|List branches by most recently committed to|git branch --sort=-committerdate| 
-|Delete a branch|git branch -d <name>| 
-|Force delete a branch|git branch -D <name>| 
- 
-==== Diff Staged/Unstaged Changes ==== 
-^Task^Command^ 
-|Diff all staged and unstaged changes|git diff HEAD| 
-|Diff just staged changes|git diff --staged| 
-|Diff just unstaged changes|git diff| 
- 
-==== Diff Commits ==== 
-^Task^Command^ 
-|Show diff between a commit and its parent|git show <commit>| 
-|Diff two commits|git diff <commit> <commit>| 
-|Diff one file since a commit|git diff <commit> <file>| 
-|Show a summary of a diff|git diff <commit> --stat \\ git show <commit> --stat| 
- 
-==== Discard Your Changes ==== 
-^Task^Command^ 
-|Delete unstaged changes to one file|git restore <file> OR \\ git checkout <file>| 
-|Delete all staged and unstaged changes to one file| git restore --staged --worktree <file> OR \\ git checkout HEAD <file>| 
-|Delete all staged and unstaged changes|git reset --hard| 
-|Delete untracked files|git clean| 
-|'Stash' all staged and unstaged changes|git stash| 
- 
-==== Edit History ==== 
-^Task^Command^ 
-|"Undo" the most recent commit (keep your working directory the same)|git reset HEAD%%^%%| 
-|Squash the last 5 commits into one|git rebase -i HEAD~6 \\ Then change "pick" to "fixup" for any commit you want to combine with the previous one| 
-|Undo a failed rebase|git reflog BRANCHNAME \\ Then manually find the right commit ID in the reflog, then run: \\ git reset --hard <commit>| 
-|Change a commit message (or add a file you forgot)|git commit --amend| 
- 
-==== Code Archaeology ==== 
-^Task^Command^ 
-|Look at a branch's history| git log main \\ git log --graph main \\ git log --oneline| 
-|Show every commit that modified a file| git log <file>| 
-|Show every commit that modified a file, including before it was renamed| git log --follow <file>| 
-|Find every commit that added or removed some text|git log -G banana| 
-|Show who last changed each line of a file|git blame <file>| 
- 
-==== Combine Diverged Branches ==== 
-^Task^Command^ 
-|Combine with Rebase|git switch banana \\ git rebase main \\ \\ Before \\ {{ :computing:git-combine-rebase-before.svg?200 |}} \\ After \\ {{ :computing:git-combine-rebase-after.svg?200 |}}| 
-|Combine with Merge|git switch main \\ git merge banana \\ \\ Before \\ {{ :computing:git-combine-merge-before.svg?200 |}} \\ After \\ {{ :computing:git-combine-merge-after.svg?200 |}}| 
-|Combine with Square Merge|git switch main \\ git merge --squash banana \\ git commit \\ \\ Before \\ {{ :computing:git-combine-square-merge-before.svg?200 |}} \\ After \\ {{ :computing:git-combine-square-merge-after.svg?200 |}}| 
- 
-|Bring a branch up to date with another branch (aka "fast-forward merge")| git switch main \\ git merge banana \\ git commit \\ \\ Before \\ {{ :computing:git-combine-ffw-copy-before.svg?200 |}} \\ After \\ {{ :computing:git-combine-ffw-copy-after.svg?200 |}}| 
- 
-|Copy one commit onto the current branch| git cherry-pick <commit> \\ \\ Before \\ {{ :computing:git-combine-ffw-copy-before.svg?200 |}} \\ After \\ {{ :computing:git-combine-ffw-copy-after.svg?200 |}}| 
- 
- 
- 
-==== Important Files ==== 
-^Task^Command^ 
-|Local git config|.git/config| 
-|Global git config|~/.gitconfig| 
-|List of files to ignore|.gitignore| 
- 
-==== Links ==== 
-  * [[https://git-scm.com/cheat-sheet|Cheat Sheet]] 
computing/git.1777199900.txt.gz · Last modified: by oscar