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
git:crib [2019/08/29 09:06]
dyson [Get existing remote branch]
git:crib [2019/12/18 20:19] (current)
admin
Line 1: Line 1:
 ====== git cribsheet ====== ====== git cribsheet ======
-https://​mirrors.edge.kernel.org/​pub/​software/​scm/​git/docs/user-manual.html#​git-concepts +===== Undo ===== 
-===== Discard local changes ​=====+==== Unstage file ==== 
 +  * ''​git reset %%--%% <​filename>''​ 
 + 
 +==== Discard local change to file ==== 
 +  * ''​git checkout %%--%% <​filename>''​ 
 + 
 +==== Discard ​all local changes ====
   * ''​git fetch''​   * ''​git fetch''​
   * ''​git checkout <​branch>''​   * ''​git checkout <​branch>''​
Line 8: Line 14:
 This is a specific form of ''​git reset %%--%%hard <​commit>''​ which resets your current branch to ''<​commit>''​. ''​origin/<​branch>''​ here refers to the HEAD commit of that branch at origin. This is a specific form of ''​git reset %%--%%hard <​commit>''​ which resets your current branch to ''<​commit>''​. ''​origin/<​branch>''​ here refers to the HEAD commit of that branch at origin.
  
-===== Unstage file ===== +==== Revert ​====
-  * ''​git reset %%--%% <​filename>''​+
  
-===== Discard change to file ===== +  * ''​git revert ref_spec''​ 
-  * ''​git checkout %%--%% <filename>''​+Git revert undoes a **single** specified commit, making the changes necessary to do so at the HEAD of your current branch. 
 + 
 + 
 +===== Branches ​===== 
 +==== Get existing remote branch ==== 
 + 
 +https://​stackoverflow.com/​questions/​9537392/​git-fetch-remote-branch 
 +  * ''​git checkout %%--%%track origin/​remote_branch_name''​ 
 + 
 +==== Branch deletion ==== 
 + 
 +=== Local branches === 
 +  ** ''​git branch -d <branch_name>''​ 
 +  .. ''​-D''​ to force deletion in the presence of local-only changes 
 + 
 +=== Remote branches === 
 +https://​stackoverflow.com/​questions/​2003505/​how-do-i-delete-a-git-branch-locally-and-remotely 
 +  ** ''​git push -d origin <​branch>''​ 
 +  .. (Substitute ''​origin''​ for a different remote name if required). 
 +=== Obsolete tracking branches === 
 +https://​stackoverflow.com/​questions/​7726949/​remove-tracking-branches-no-longer-on-remote 
 +  * ''​git remote prune origin''​
 ===== List conflicted files ===== ===== List conflicted files =====
   * ''​git diff %%--%%name-only %%--%%diff-filter=U''​   * ''​git diff %%--%%name-only %%--%%diff-filter=U''​
 Show //​unmerged//​ files in the diff between the working tree and the index (staging area for next commit). Show //​unmerged//​ files in the diff between the working tree and the index (staging area for next commit).
  
-===== Unable to get local issuer certificate  ​=====+===== Configuration ===== 
 +==== Config files ==== 
 +git has [[https://​www.theserverside.com/​blog/​Coffee-Talk-Java-News-Stories-and-Opinions/​Where-system-global-and-local-Windows-Git-config-files-are-saved|three config files]]. In Windows: 
 +  * system-wide ("​system"​) -- ''​gitconfig''​ in the git install folder'​s ''​mingw64\etc''​ subdirectory (probably ''​C:​\Program Files\Git\mingw64\etc''​) 
 +  * per-user ("​global"​) --  ''​.gitconfig''​ in the root of the user's local profile 
 +  * per-repo ("​local"​) -- ''​config''​ in the repo's ''​.git''​ folder  
 +Settings are overridden by values in more narrowly-scoped config (e.g. if the same property is set at user and repo level, the repo level takes precedence). 
 + 
 +=== Can't find them? === 
 +Inspect properties to see where their values are set: 
 +  * ''​git config %%--%%list %%--%%show-origin''​ 
 +or just edit them (using the [[#​editor|configured editor]]) via the command line: 
 +  * ''​git config %%--%%edit %%--%%system'' ​  
 +  * ''​git config %%--%%edit %%--%%global'' ​  
 +  * ''​git config %%--%%edit %%--%%local'' ​  
 + 
 +==== Settings ==== 
 +https://​www.atlassian.com/​git/​tutorials/​setting-up-a-repository/​git-config covers a lot of possible settings. 
 +=== Editor === 
 +By default the mighty [[https://​www.vim.org/​|vim]]. If that's not your cup of tea: 
 +  * ''​git config %%--%%global core.editor %%"​%%'​C:/​Program Files/​Notepad++/​notepad++.exe'​ -multiInst -notabbar -nosession -noPlugin%%"​%%''​ 
 + 
 +=== Terminal colours === 
 +Here's a possible config setup (thanks [[https://​nathanhoad.net/​how-to-colours-in-git/​|Nathan Hoad]]!) 
 +<​code>​[color] 
 +  ui = auto 
 +[color "​branch"​] 
 +  current = yellow reverse 
 +  local = yellow 
 +  remote = green 
 +[color "​diff"​] 
 +  meta = yellow bold 
 +  frag = magenta bold 
 +  old = red bold 
 +  new = green bold 
 +[color "​status"​] 
 +  added = green bold 
 +  changed = yellow bold 
 +  untracked = magenta bold</​code>​ 
 +To set these up via the command line (e.g. for current branch as above): 
 +  * ''​git config %%--%%global color.branch.current %%"​%%yellow reverse%%"​%%''​ 
 + 
 + 
 +=== Unable to get local issuer certificate ​ ===
  
   ** To disable verification:​   ** To disable verification:​
-  .. ''​git config --global http.sslVerify false''​+  .. ''​git config ​%%--%%global http.sslVerify false''​
   .. This is ill-advised as it [[https://​stackoverflow.com/​questions/​23885449/​unable-to-resolve-unable-to-get-local-issuer-certificate-using-git-on-windows/​38460722|opens you up to man-in-the-middle attacks]].   .. This is ill-advised as it [[https://​stackoverflow.com/​questions/​23885449/​unable-to-resolve-unable-to-get-local-issuer-certificate-using-git-on-windows/​38460722|opens you up to man-in-the-middle attacks]].
  
-===== Get existing remote branch ​===== +===== Useful links =====
- +
-https://​stackoverflow.com/​questions/​9537392/​git-fetch-remote-branch +
-  * ''​git checkout --track origin/​remote_branch_name''​+
  
 +  * https://​mirrors.edge.kernel.org/​pub/​software/​scm/​git/​docs/​user-manual.html#​git-concepts
 +  * http://​git-school.github.io/​visualizing-git/​
    
 {{tag> git}} {{tag> git}}