Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Not intro to git

Keith Dahlby edited this page Oct 26, 2013 · 17 revisions

Convened by Keith Dahlby @dahlbyk

  • git rebase --interactive for rewriting history
    • --autosquash is awesome - set rebase.autosquash = true
    • With commit --[fixup|squash] <ref>, --autosquash is even more awesome
  • git add --patch for staging only parts of a change
    • Also reset -p to unstage, checkout -p to discard, and stash save -p to stash
  • git bisect for binary search through commit space
    • Something broke between v1 tag and now?
      > git bisect start HEAD v1
      Bisecting: 4 revisions left to test after this
      > # Does the bug exist in this commit? Yes!
      > git bisect bad
      Bisecting: 2 revisions left to test after this
      > # Does the bug exist in this commit? No!
      > git bisect good
      Bisecting: 0 revisions left to test after this
      > # Does the bug exist in this commit? Yes!
      > git bisect bad
      5087d6… is the first bad commit
      > git bisect reset
      
    • Run bisect with a batch file: git bisect run cmd "/c tests.bat"

What is .gitattributes

How to treat files by their extensions.

# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs     diff=csharp
*.sln    merge=union
*.csproj merge=union

Specifying diff=csharp makes a diff show the method which the diff exists, for instance:

diff --git a/src/Templates/App_Architecture/Activators/WindsorActivator.cs b/src
index 2e7bfd5..16cdeed 100644
--- a/src/Templates/App_Architecture/Activators/WindsorActivator.cs
+++ b/src/Templates/App_Architecture/Activators/WindsorActivator.cs
@@ -34,9 +34,6 @@ public static void Startup()
                 Component.For<IWindsorContainer>().Instance(IoC.Container)
                 );
 
-            // Search for an use all installers in this application.
-            IoC.Container.Install(FromAssembly.This());
-
             // Our configuration magic, register all interfaces ending in Confi
             // this assembly, and create implementations using DictionaryAdapte
             // from the AppSettings in our app.config.

List of all possible languages available at : http://git-scm.com/docs/gitattributes

  • ada suitable for source code in the Ada language.
  • bibtex suitable for files with BibTeX coded references.
  • cpp suitable for source code in the C and C++ languages.
  • csharp suitable for source code in the C# language.
  • fortran suitable for source code in the Fortran language.
  • html suitable for HTML/XHTML documents.
  • java suitable for source code in the Java language.
  • matlab suitable for source code in the MATLAB language.
  • objc suitable for source code in the Objective-C language.
  • pascal suitable for source code in the Pascal/Delphi language.
  • perl suitable for source code in the Perl language.
  • php suitable for source code in the PHP language.
  • python suitable for source code in the Python language.
  • ruby suitable for source code in the Ruby language.
  • tex suitable for source code for LaTeX documents.

Submodules

Reference to another repository at a specific commit within your repository

Merge Tools

  • Beyond Compare

Git Aliases

@dahlbyk has SVN aliases http://bit.ly/better-git-svn

@dahlbyk's other aliases

[alias]
	# For email code review
	fp = format-patch -C --no-binary -o c:/Dev/Patches

	# Rebase current branch on origin/master, and keep local master in sync
	up = !git fetch --all --prune && git rebase origin/master && git submodule update && git push . origin/master:master 2> /dev/null

	# Push current branch/ref to origin/master and local master
	pub = !git push origin HEAD:master && git push . HEAD:master && git checkout master

	# Inspired by http://bit.ly/git-lg
	lg = log -w -C --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
	la = log -w -C --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
	lb = log -w -C --branches --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

	# Ignore whitespace, detect copies
	# -C shouldn't be necessary if you set config.renames = copies
	dd = diff -w -C

	# Commits since master, in reverse (oldest first) order
	new = log -w -C --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --reverse master..

	# Loves me some interactive rebase
	rbc = rebase --continue
	rbi = rebase --interactive
	rbe = rebase --edit-todo   # Relatively new - edit TODO list for active rebase

	# Merge index into last commit, reusing commit metadata
	cia = commit --amend -C HEAD
	ciar = commit --amend -C HEAD --reset-author

	# See also posh-git's Delete-MergedBranches
	bm = branch --merged

	# Trivial
	mt = mergetool
	dt = difftool
	co = checkout
	cob = checkout -b
	nb = checkout master -b     # nb = new topic branch from master

	# Difference between HEAD and index, i.e. what will be committed
	di = diff --staged

	# Patchwise stage all changes
	ap = add -Ap

	# Similar to lb, but less fancy and includes diff stat
	lbr = log --oneline --graph --stat --branches --decorate master..

	# Undo last commit, but leave index unchanged (--soft)
	unci = reset --soft HEAD@{1}

@jflanagan mentioned his favorite alias - shows branches by order of most recent commit:

#  http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches
brd = "! f() { for k in $(git branch $@ | sed 's/^..//; s/ .*//'); do  echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ;  done | sort -r; }; f"

@TRayburn has a chocolatey package for his aliases at cinst TimRayburn.GitAliases

How to see pull requests in log

fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

git config -e opens your config in your favorite editor

How to remove a directory from the entire history (i.e. remove packages directory)

http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository

Keith @ NDC: Git More Done

http://vimeo.com/43659036