4

Anyone have some gems for git that should be added to every base install? Some cool commands that you cant live without, thus add them to your .gitconfig [alias]'s

ps: seen some questions like this about other things, hope its the best place

dogmatic69
  • 7,511
  • 3
  • 29
  • 49
  • this question is no different to something like http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read or http://stackoverflow.com/questions/194812/list-of-freely-available-programming-books or http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined and http://stackoverflow.com/questions/9033/hidden-features-of-c so dont know why people want to close it :/ – dogmatic69 Mar 23 '11 at 20:33
  • 1
    This question has to be community wiki. – gotgenes Mar 23 '11 at 20:53
  • i was thinking the same, could not find that option – dogmatic69 Mar 23 '11 at 20:56
  • @gotgenes, @dogmatic: The reason that the community wiki option is disabled is that people, for some reason, think that it's a way to ask bad questions. There is no way to provide a good single answer to this question, only a decent answer among many, and its scope is broad. The "not a real question" close reason is described as: "This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form." That's a perfect fit. – Cascabel Mar 23 '11 at 20:58
  • 1
    @Jefromi: Which of those qualifications do you think applies to this question? I understand what the question is asking (neither ambiguous nor vague nor incomplete), the question specifically relates to git commands (not overly broad), the author clearly expects a reply (not rhetorical), and already we have several reasonable answers. The question is banal but it is still helpful. My only contention is that because it cannot be completely answered, it must be community wiki. – gotgenes Mar 23 '11 at 21:12
  • @gotgenes: It's overly broad. "Relates specifically to git commands" is not specific. Look up and right - the git tag has nearly 7000 questions. "because it cannot be completely answered, it must be community wiki" - so it can't be reasonably answered, eh? Sound familiar? Community wiki is not an excuse for bad questions. – Cascabel Mar 23 '11 at 21:33

3 Answers3

2

One I've recently discovered that I quite like is actually in the contrib dir of git, so it's easy to get: It's called git new-workdir

It allows you to create a second working directory for a repository, without duplicating the entire repository. This allows you to work in two separate branches simultaneously, which has come in quite handy for me.

Jason LeBrun
  • 12,041
  • 2
  • 40
  • 40
  • cool, a bit more information about this for anyone else wondering what they would need this for... http://nuclearsquid.com/writings/git-new-workdir.html – dogmatic69 Mar 23 '11 at 20:29
  • Another note: the place where it's been the most handy for me recently is when I'm switching between two branches where the branches are different enough to require a large recompile when switching. By maintaining two separate working copies, I can avoid having to rebuild everything when I switch branches. – Jason LeBrun Mar 23 '11 at 20:31
1

some of the ones i got (off random sites, don't remember where)

for a pretty treeish view of all the commits:

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

get the last commiter

whois = "!sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"

show the last commit

whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
dogmatic69
  • 7,511
  • 3
  • 29
  • 49
1

This will give you la and lc which shows you a oneline log strictly ordered by 'author' or 'commit' date respectively. The 'u' in the pretty specifications relates to "unix timestamp". The unix timestamp is only included for sorting and stripped later. An ISO version of the time remains.

alias.la=! log () { git log --pretty=lau $1 | sort -rn | cut -d " " -f 2- | less ; } ; log  
alias.lc=! log () { git log --pretty=lcu $1 | sort -rn | cut -d " " -f 2- | less ; } ; log
pretty.lau=format:%at %C(dim yellow)%h %C(cyan)%ai%Cgreen%d %Creset%s
pretty.lcu=format:%ct %C(dim yellow)%h %C(cyan)%ci%Cgreen%d %Creset%s

Usage is git la <commit specifiers>, so could be git la or git la branch or git la C1..C2. Note however, that the .. still acts in the usual log way. Sorting is only post-processing.

And here is another one:

> cat ~/bin/git-advance 
#!/bin/bash
C="`git log --first-parent --format=%H ..$1 -- | tail -1`"
if [ -z "$C" ]; then
    echo "Could not determine next commit"
    exit 1
fi
git checkout "$C"

And then of course, alias.advance=! git-advance. Usage is git advance <future-commit> and will checkout the next commit from current HEAD towards the given <future-commit>. This will result in a detached HEAD but I find it handy for propagating commits from git to another VCS manually. No guarantees, didn't try it on complicated histories yet.

Here is something experimental for missed renames in merge conflicts:

https://gist.github.com/894374

Tilman Vogel
  • 8,221
  • 4
  • 29
  • 30
  • got any more info on how you implement this? not the usual [alias] ... stuff ive seen in .gitconfig – dogmatic69 Mar 23 '11 at 20:57
  • @dogmatic69 The `!` makes the rest to be executed in the shell. The `log () {... ;} ; log ` construct is a trick to put the argument to `git la` at the right place. `git` will just append the argument to the alias. – Tilman Vogel Mar 23 '11 at 21:01
  • awesome one, always been looking for a way to go forward though a git tree. That one will be handy – dogmatic69 Mar 23 '11 at 21:19
  • @dogmatic: A great many times when you think that you want to go back in history, then step forward, are actually use cases for `git bisect`. – Cascabel Mar 23 '11 at 21:37