Difference between revisions of "User:PEZ/Git things"

From Robowiki
Jump to navigation Jump to search
(My git solutions log (mostly for my own memory, but feel free to use and contribute))
 
(About empty directories)
 
Line 7: Line 7:
 
A few days ago I found this really cool site about figuring git out: http://think-like-a-git.net/ It's really fun to read too.
 
A few days ago I found this really cool site about figuring git out: http://think-like-a-git.net/ It's really fun to read too.
  
== Colors ==
+
== Git and empty directories ==
Colored highlights help me a lot when trying to make sense of Git output. I have this in my ~/.gitconfig:
+
 
 +
Git isn't designed to track directories. It tracks files. The best way to still keep directories needed for structure is to add ''.gitignore'' files to the directories with this content:
 +
 
 +
    # Ignore everything in this directory
 +
    *
 +
    # Except this file
 +
    !.gitignore
 +
 
 +
Here's the [http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository/932982#932982 Stackoverflow answer] that taught me this. Upvote!
 +
 
 +
== Gitconfig ==
 +
 
 +
Some things to consider keeping in ''~/.gitconfig''.
 +
 
 +
=== Colors ===
 +
Colored highlights help me a lot when trying to make sense of Git output.
  
 
     [color]
 
     [color]
 
       ui = true
 
       ui = true
  
== Graph log ==
+
=== Graph log ===
  
 
Yes, a GUI tool is often best to get an overview of the history. But I tend to stay at my prompt often and then this alias comes in handy:
 
Yes, a GUI tool is often best to get an overview of the history. But I tend to stay at my prompt often and then this alias comes in handy:
Line 19: Line 34:
 
     [alias]
 
     [alias]
 
       lg = log --graph --color --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
 
       lg = log --graph --color --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
 
(Add to your .gitconfig.)
 
  
 
== Oneliners ==
 
== Oneliners ==

Latest revision as of 14:11, 13 November 2011

Thought I could use a wiki page here as a solutions log for git tricks I stumble across.

Resources

The Git Pro book and site has been absolutely invaluable to me to get rid of the feeling that Git always surprises me. http://progit.org/ I have the .epub on both my iPhone and iPad.

A few days ago I found this really cool site about figuring git out: http://think-like-a-git.net/ It's really fun to read too.

Git and empty directories

Git isn't designed to track directories. It tracks files. The best way to still keep directories needed for structure is to add .gitignore files to the directories with this content:

   # Ignore everything in this directory
   *
   # Except this file
   !.gitignore

Here's the Stackoverflow answer that taught me this. Upvote!

Gitconfig

Some things to consider keeping in ~/.gitconfig.

Colors

Colored highlights help me a lot when trying to make sense of Git output.

   [color]
     ui = true

Graph log

Yes, a GUI tool is often best to get an overview of the history. But I tend to stay at my prompt often and then this alias comes in handy:

   [alias]
     lg = log --graph --color --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

Oneliners

(Of course, some of these can be turned into git aliases or functions in your shell if you find you use them often.)

git summary

A bit like hg summary.

   $ git log -1 --summary --stat

Undelete

You knew there was a file named foo.txt some time ago and want it back? Try this:

   $ git rev-list -n 1 HEAD -- foo.txt
   b193eecf895e45b4f875eb4e6030f2c2e9fac897
   $ git checkout b193eecf895e45^ -- foo.txt