r/programming • • Feb 06 '15

Git 2.3 has been released

https://github.com/blog/1957-git-2-3-has-been-released
622 Upvotes

307 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Feb 06 '15

[deleted]

0

u/[deleted] Feb 06 '15

[deleted]

25

u/bundt_chi Feb 06 '15

Is gitk not suffcient for your needs ?

8

u/dontdieych Feb 06 '15

I also love gitk. Very handy and powerful. Give it a chance.

21

u/deafbybeheading Feb 06 '15

I agree, but git log --all --graph --decorate does go a long way.

7

u/SemiNormal Feb 06 '15

git log --all --graph --decorate

This is my main complaint when using git. Why does the most basic of functions --always --require --several --switches? Aliases are just a crutch.

13

u/HeroesGrave Feb 06 '15

To be fair, turning the commit log into a graph is not basic functionality.

4

u/[deleted] Feb 06 '15

It's not, because it requires a ton of switches... If it would be something like git prettygraph it would be a basic functionality. I'm claiming chicken/egg here because a graph is more than useful.

→ More replies (2)

2

u/[deleted] Feb 07 '15

I don't know. "History is a DAG" is a pretty core part of git, so I think it's reasonable to call viewing the history as a graph basic functionality.

2

u/Poyeyo Feb 06 '15

All my aliases are in a git repository.

0

u/[deleted] Feb 06 '15

[deleted]

4

u/gfixler Feb 06 '15

I have these in my ~/.gitconfig:

la = log --oneline --graph --all --decorate
lb = log --oneline --graph --decorate

I also have this script on my path as git-las:

#!/bin/bash

height=$(tput lines)
height=$((height / 3))
git la -$height

I tried to do that as an alias, as a function alias, and with the help of #git and /r/git, but nothing doing. It needs to be a script, apparently. I also have a git-lass version that changes the 3 to a 6. Basically I can do git la (list all) to get a full [possibly paged] output, or git las (list all short) to fire off the script and get the same thing truncated to roughly 1/3rd of my terminal height, or git lass (list all super short) for about 1/6th the height. I git las instantly and all day long. It's not exact, because branches and merges add in a fluctuating number of extra lines between the --oneline output, but it's good enough for me. I work on a variety of monitors, from zoomed-in laptop terminals with 30 lines, to my 24" vertical work monitor with well over 100 lines, and having these things in my dotfiles means I get nice behavior everywhere. I can see existing output, along with some commit oneliner info.

I also have git-lbs and git-lbss (b for 'branch'), but basically never use any of the git lb* aliases and scripts. I seem to always want to see everything. I've used git for 2 years to great effect, and I've never used one of the UIs. I find they tie my hands. Look into fugitive (for Vim) and magit (for Emacs), too. They make git ridiculously speedy to work with, and eliminate a lot of the need for the terminal uses, especially if you have a host of mappings (Vim), as I do:

nnoremap <Leader>gs :Gstatus<CR>
nnoremap <Leader>gd :Gvdiff<CR>
nnoremap <Leader>gD :Gsdiff<CR>
nnoremap <Leader>gb :Gblame<CR>
nnoremap <Leader>gB :Git checkout -b<Space>
nnoremap <Leader>gf :Git fetch<CR>
nnoremap <Leader>gL :exe ':!cd ' . expand('%:p:h') . '; git la'<CR>
nnoremap <Leader>gl :exe ':!cd ' . expand('%:p:h') . '; git las'<CR>
nnoremap <Leader>gm :Git merge<CR>
nnoremap <Leader>gh :Silent Glog<CR>
nnoremap <Leader>gH :Silent Glog<CR>:set nofoldenable<CR>
nnoremap <Leader>gr :Gread<CR>
nnoremap <Leader>gw :Gwrite<CR>
nnoremap <Leader>gp :Git push<CR>
nnoremap <Leader>g- :Silent Git stash<CR>:e<CR>
nnoremap <Leader>g+ :Silent Git stash pop<CR>:e<CR>
nnoremap <Leader>gu :GitGutterRevertHunk<CR>
nnoremap <Leader>ct :Git ctags<CR>

That last one is based on this, which took a bit of finessing to get set up right, but has made ctags a completely automated thing for me for a long time now.

I also use git-gutter (Vim) constantly/passively to show me where my changes are, and to ]c and [c hop between them, and vim-gitv very occasionally to see the graph, but my ,gl alias (Vim, above), which prints out the output of git las for me, and ,gL, which does git la are usually more than enough to get an instant idea of what's going on with my branches and commits. The UIs are so much slower.

2

u/ForeverAlot Feb 06 '15
la = log --oneline --graph --all --decorate
las = "!git la -$(($(tput lines) / 3))"
lasf = "!f() { git la -$(($(tput lines) / 3)); } && f"

?

The only log alias I have is

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

which is mostly a custom format of

log --oneline --decorate --graph
→ More replies (2)
→ More replies (4)

3

u/ForeverAlot Feb 06 '15

I also add --oneline.

→ More replies (2)

2

u/Tblue Feb 06 '15

tig is also nice.

→ More replies (1)

18

u/[deleted] Feb 06 '15

Partial file staging is why I use a gui.

40

u/haakon Feb 06 '15

git add -p is easy enough.

5

u/isarl Feb 06 '15

I use that one all the time. Every once in a while, though, I have adjacent but unrelated changes, and then I love being able to do it line-by-line with fugitive.

10

u/[deleted] Feb 06 '15

Use "e" (like "edit") when asked whether you want to stage a hunk and remove the new lines you don't want to stage and add the old lines that you don't want removed in that commit.

2

u/Already__Taken Feb 06 '15

Fuck knows how it wants me to adjust those line numbers though. Why can't the commit editor just deal with it.

2

u/ForeverAlot Feb 06 '15

You can mostly ignore them!

  • Anything can be added as a + line.

  • Any + line can be removed or moved anywhere else in the hunk.

  • Any - line can be changed to a [] line.

  • Most [] lines can be changed to - lines. [] lines supply the context Git needs to apply patches, and a missing or non-existent [] are often the cause of a patch failure.

This works without touching the patch line numbers at all.

→ More replies (1)

2

u/[deleted] Feb 06 '15

Which gui do you use and does it support the "e (edit)" command when partially staging?

4

u/Funnnny Feb 06 '15

I'm using magit as my git GUI. I know git add patch is nice an all. But using magit to add a hunk or edit it is so much easier.

2

u/gfixler Feb 06 '15

Well, now there are 2 of us.

→ More replies (5)