User Tools

Site Tools


quickref:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
quickref:git [2013/10/30 12:24]
andy [git diff] Clarified diff revision specification.
quickref:git [2015/07/02 11:36]
andy [Staging Files]
Line 155: Line 155:
 </​file>​ </​file>​
  
-This sample output shows **six locally modified** files, ​none of which have any unstaged ​changes. Entering **''​2''​** enters the **update** mode, and then one or more files can be selected to be staged. Files can be specified in the following ways:+This sample output shows **six locally modified** files -- for example''​README.txt''​ has six lines added and four lines removed. None of the files have any **staged ​changes** however. 
 + 
 +Entering **''​2''​** enters the **update** mode, and then one or more files can be selected to be staged. Files can be specified in at least the following ways:
  
 ^ ''​3''​ | Add a single file specified by number. | ^ ''​3''​ | Add a single file specified by number. |
Line 179: Line 181:
 What now> What now>
 </​file>​ </​file>​
 +
 +Now we can see that changes have moved from the working directory into the index for those files that we've staged. If we made further modifications to the same files before committing then we'd see change summaries in both columns, since the staged files would differ from the current HEAD and the working directory copies would also differ from the staged ones.
  
 The other options perform the following functions: The other options perform the following functions:
Line 2031: Line 2035:
  
 <file - .gitconfig>​ <file - .gitconfig>​
-[user] +        ​name = Andy Pearce
- name = Andy Pearce +
- email = andy@andy-pearce.com+
 [merge] [merge]
- conflictstyle ​diff3 +        tool vimdiff 
- tool meld+        ​defaultToUpstream ​true
 [diff] [diff]
- tool = meld+        ​tool = vimdiff
 [color] [color]
- ui = true+        ​ui = true
 [color "​branch"​] [color "​branch"​]
- current = green bold +        ​current = green bold 
- local = green +        local = green 
- remote = blue +        remote = black bold 
- plain = red+        plain = red
 [color "​diff"​] [color "​diff"​]
- plain = white +        ​plain = white 
- meta = white blue bold +        meta = yellow ​blue bold 
- frag = blue bold +        frag = white blue bold 
- func = blue bold +        func = white blue 
- old = red bold +        old = red 
- new = green bold +        new = green 
- commit = white bold +        commit = yellow 
- whitespace = white red+        whitespace = red reverse
 [color "​decorate"​] [color "​decorate"​]
- branch = green +        ​branch = green 
- remoteBranch = blue +        remoteBranch = black bold 
- tag = red +        tag = red 
- stash = cyan +        stash = blue bold 
- HEAD = yellow+        HEAD = yellow ​bold
 [color "​grep"​] [color "​grep"​]
- context = cyan +        ​context = cyan 
- filename = magenta +        filename = magenta 
- function = white blue bold +        function = white blue bold 
- linenumber = green +        linenumber = green 
- match = yellow bold +        match = yellow bold 
- selected = white +        selected = white 
- separator = cyan+        separator = cyan
 [color "​interactive"​] [color "​interactive"​]
- prompt = white bold +        ​prompt = white bold 
- header = blue bold +        header = blue bold 
- help = green +        help = green 
- error = red bold+        error = red bold
 [color "​status"​] [color "​status"​]
- header = blue bold +        ​header = blue bold 
- added = green +        added = green 
- updated = green +        updated = green 
- changed = red bold +        changed = red bold 
- untracked = cyan +        untracked = cyan 
- branch = green bold +        branch = green bold 
- nobranch = white red bold+        nobranch = white red bold 
 +[init] 
 +        templatedir = /​home/​apearce16/​.git_template 
 +[alias] 
 +        aliases = "!git config --list | grep ^alias"​ 
 +        branches = for-each-ref --sort=-committerdate --format='​%(color:​cyan)|%(committerdate:​relative)| %(color:​yellow bold)%(refname:​short)'​ refs/​heads 
 +        branchgraph = log --graph --abbrev-commit --decorate --simplify-by-decoration --date=relative --all --pretty=format:"​%C(yellow)%h\\ %C(cyan)|%ad|%C(yellow)%C(bold)%d\\ %Creset%s%C(green)\\ [%an]%C(blue)%C(bold)\\ <​%cn>"​ 
 +        branchhistory = "!git showline HEAD; git showline @{-1}; git showline @{-2}; git showline @{-3}; git showline @{-4}; git showline @{-5}"​ 
 +        changed = diff-tree -r --no-commit-id --name-only --relative 
 +        changes = log --pretty=format:"​%C(yellow)%h\\ %C(cyan)|%ad|%C(yellow)%C(bold)%d\\ %Creset%s%C(green)\\ [%an]%C(blue)%C(bold)\\ <​%cn>"​ --decorate --stat --date=relative 
 +        commits = log --pretty=format:"​%C(yellow)%h\\ %C(cyan)|%ad|%C(yellow)%C(bold)%d\\ %Creset%s%C(green)\\ [%an]%C(blue)%C(bold)\\ <​%cn>"​ --decorate --date=relative 
 +        ctags = !.git/​hooks/​ctags 
 +        fe = fetch --prune 
 +        ff = merge --ff-only 
 +        graph = log --graph --abbrev-commit --decorate --date=relative --all --pretty=format:"​%C(yellow)%h\\ %C(cyan)|%ad|%C(yellow)%C(bold)%d\\ %Creset%s%C(green)\\ [%an]%C(blue)%C(bold)\\ <​%cn>"​ 
 +        grepall = "!git grep --full-name -n -p" 
 +        showline = log --oneline --decorate -1 
 +        summary = show --name-status 
 +[push] 
 +        default = upstream 
 +[rebase] 
 +        autosquash = true 
 + 
 +[difftool] 
 +        prompt = false
 </​file>​ </​file>​
  
Line 2101: Line 2127:
 The following are some handy pre-canned commands for specific situations. You can set up [[https://​git.wiki.kernel.org/​index.php/​Aliases|aliases]] for these as well. The following are some handy pre-canned commands for specific situations. You can set up [[https://​git.wiki.kernel.org/​index.php/​Aliases|aliases]] for these as well.
  
-==== Log ====+==== Housekeeping ==== 
 + 
 +A good couple of aliases to run in quick succession to fetch remotes with pruning, and then fast-forward the current branch if possible: 
 + 
 +<​code>​ 
 +git fetch --prune 
 +git merge --ff-only 
 +</​code>​ 
 + 
 + 
 +==== Searching ==== 
 + 
 +Search the entire repository, regardless of the current subdirectory:​ 
 + 
 +<​code>​ 
 +git grep --full-name -n -p <​needle>​ 
 +</​code>​ 
 + 
 + 
 +==== Listing commits ​====
  
 Show recent commits with relative dates and authors: Show recent commits with relative dates and authors:
  
 <​code>​ <​code>​
-git log --pretty=format:"​%C(yellow)%h %C(cyan)%ad%C(yellow)%C(bold)%d %Creset%s%Cgreen ​[%cn]"+git log --decorate --date=relative \ 
-        --decorate --date=relative+        ​--pretty=format:"​%C(yellow)%h %C(cyan)|%ad|%C(yellow)%C(bold)%d %Creset%s%C(green) ​[%an]%C(blue)%C(bold) <%cn>"
 </​code>​ </​code>​
  
Line 2113: Line 2158:
  
 <​code>​ <​code>​
-git log --- <​filename>​+git log --- <​filename>​
 </​code>​ </​code>​
  
-Show the state of all branches and how they relate:+Show a graph of all commits:
  
 <​code>​ <​code>​
-git log --all --graph --oneline ​--decorate --simplify-by-decoration+git log --graph --abbrev-commit ​--decorate --date=relative --all \ 
 +        ​--pretty=format:"​%C(yellow)%h %C(cyan)|%ad|%C(yellow)%C(bold)%d %Creset%s%C(green) [%an]%C(blue)%C(bold) <​%cn>"​
 </​code>​ </​code>​
 +
 +As above, but only commits which are the head of a branch:
 +
 +<​code>​
 +git log --pretty=format:"​%C(yellow)%h %C(cyan)|%ad|%C(yellow)%C(bold)%d %Creset%s%C(green) [%an]%C(blue)%C(bold) <​%cn>"​ \
 +        --graph --abbrev-commit --decorate --simplify-by-decoration --date=relative --all 
 +</​code>​
 +
 +
 +==== Listing Files ====
 +
 +Show files that changed between two commits in the current directory:
 +
 +<​code>​
 +git diff-tree -r --no-commit-id --name-only --relative <​commit1>​ <​commit2>​
 +</​code>​
 +
 +
 +==== Listing Branches ====
 +
 +List branches in order of last commit time, most recent first (useful for removing dead branches):
 +
 +<​code>​
 +git for-each-ref --sort=-committerdate \
 +                 ​--format='​%(color:​cyan)|%(committerdate:​relative)| %(color:​yellow bold)%(refname:​short)'​ \
 +                 ​refs/​heads
 +</​code>​
 +
quickref/git.txt · Last modified: 2015/07/02 11:36 by andy