Git

To see the history for line 13 in the file file.xml:

$ git log --format=format:%H  file.xml | xargs -L 1 git blame file.xml -L 13,13

To see the files in a commit:

$ git diff-tree --no-commit-id --name-only -r <commit-id>

Installing

Linux

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get install git

Difftool/Mergetool

On Windows:

> git config --global difftool.gvimdiff.path "C:\Program Files (x86)\Vim\vim74\gvim.exe"
> git config --global mergetool.gvimdiff.path "C:\Program Files (x86)\Vim\vim74\gvim.exe"
> git config --global diff.tool gvimdiff
> git config --global merge.tool gvimdiff

Commit Messages

Merge vs. Rebase

Workflow models

Credential Helper

Linux

$ git config --global credential.helper "cache --timeout=3600"

or

$ git config --global credential.helper store

Note that this will store your creds in plaintext in ~/.git-credentials.

Windows

$ git config --global credential.helper wincred

AutoCrLf

core.autocrlf = false

This is the default, but most people are encouraged to change this immediately. The result of using false is that Git doesn?t ever mess with line endings on your file. You can check in files with LF or CRLF or CR or some random mix of those three and Git does not care. This can make diffs harder to read and merges more difficult. Most people working in a Unix/Linux world use this value because they don?t have CRLF problems and they don?t need Git to be doing extra work whenever files are written to the object database or written out into the working directory.

core.autocrlf = true

This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database and turn all LF back into CRLF when writing out into the working directory. This is the recommended setting on Windows because it ensures that your repository can be used on other platforms while retaining CRLF in your working directory.

core.autocrlf = input

This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database. It will not, however, do the reverse. When you read files back out of the object database and write them into the working directory they will still have LFs to denote the end of line. This setting is generally used on Unix/Linux/OS X to prevent CRLFs from getting written into the repository. The idea being that if you pasted code from a web browser and accidentally got CRLFs into one of your files, Git would make sure they were replaced with LFs when you wrote to the object database.

Use .gitattributes to specify the line endings for a specific file:

vimfiles/notes.txt text eol=lf

Tags

To add a tag:

$ git tag new-tag

To list tags:

$ git tag

To push tags:

$ git push origin --tags

Init bare repo on UNC path

git init --bare \\server\path\repo.git
git clone //server/path/repo.git

git-log

'git log' [<options>] [<revision range>] [[\--] <path>...]

Commonly Ignored Files

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.unsuccessfulbuild
*.psess
*.vspx
*.etl

ipch/
obj/
[Bb]in
[Dd]ebug/
[Rr]elease/
Ankh.NoLoad
~AutoRecover*

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
_viminfo

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

#NuGet
packages/

#vim
_viminfo
*~
*.swp
*.swo

# Java class files
*.class

# android: built application files
*.apk
*.ap_

# android: files for the dex VM
*.dex

# android: generated files
bin/
gen/

# android: Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.metadata
# .project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

Git Grep

  • git grep text (ignores .ignore files)
  • git log –grep=text (filter commits with text in the message)
  • git log -Stext (pickaxe: find text that was added or removed by a commit)