TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Little Things I Like to Do with Git

656 pointsby csswizardryabout 8 years ago

22 comments

TimWollaabout 8 years ago
Since git 2.9 there is another experimental, opt-in, improvement to git diff that results in more readable diffs: Heuristics that try to capture the logical changes better. By default git tries to delay the start of diffs as long as possible leading to bogus highlighting of e.g. doc comments (slash star star).<p>See <a href="https:&#x2F;&#x2F;github.com&#x2F;blog&#x2F;2188-git-2-9-has-been-released" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;blog&#x2F;2188-git-2-9-has-been-released</a> (section Beautiful diffs) for an example and <a href="http:&#x2F;&#x2F;blog.deveo.com&#x2F;whats-new-in-git-2-11&#x2F;#experimentalheuristicsgitdiff" rel="nofollow">http:&#x2F;&#x2F;blog.deveo.com&#x2F;whats-new-in-git-2-11&#x2F;#experimentalheu...</a> for another similar option that I did not try yet.
评论 #14410609 未加载
qzncabout 8 years ago
Things in my dot repo [0]:<p>git-overview: Short report about top committers, files with most commits and most authors. Nice when you checkout a non-trivial repo for the first time.<p>git-onNotify: Do something (like `make`) whenever a tracked file changes. Usually used to build LaTeX and static websites.<p>git-randomline: Chooses a random file and a random line number there. The game is explain that single line to some fellow. Do this repeatedly to spread knowledge about a codebase.<p>git-tarball: Pack the repo into a tar.bz2 file.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;qznc&#x2F;dot&#x2F;tree&#x2F;master&#x2F;bin" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;qznc&#x2F;dot&#x2F;tree&#x2F;master&#x2F;bin</a>
评论 #14410120 未加载
nicwolffabout 8 years ago
I have his &quot;git recent&quot; alias, and then in .bashrc<p><pre><code> alias co=&#x27;select br in $(git recent); do git co $br; break; done&#x27; </code></pre> so when I type &quot;co&quot; at the command prompt I get a numbered menu of branches in the order I last checked them out, and can just type a branch&#x27;s number and hit return to check it out again.
评论 #14412971 未加载
qzncabout 8 years ago
I also have aliases in my shell instead of git aliases.<p><pre><code> st git status ... gl git log ... gd git diff ... gg gitg gup git pull --rebase gb git branch </code></pre> The dots mean there are more arguments. The point is, every once in a while I analyse my shell history and add aliases for the most used commands. Looking at it now, it seems I should add aliases for `git push` and `vi Makefile`.<p>I also have the aliases g for git, m for make, and v for vim.
评论 #14410140 未加载
评论 #14411489 未加载
评论 #14413706 未加载
评论 #14411201 未加载
评论 #14412584 未加载
ericfrederichabout 8 years ago
I like how he creates an alias to blame called praise. He&#x27;s right, blame is a loaded word. The command I really use to &quot;blame&quot; people is bisect... though sometimes I use that to find something good too
评论 #14410868 未加载
评论 #14409886 未加载
评论 #14410585 未加载
评论 #14413547 未加载
评论 #14413810 未加载
评论 #14412328 未加载
thedenabout 8 years ago
I use this alias to quickly cd to the root directory of a repo. Useful if you&#x27;re way deep in a repo and need to back out.<p><pre><code> alias gitroot=&#x27;cd $(git rev-parse --show-toplevel) &amp;&amp; echo &quot;$_&quot;&#x27;</code></pre>
评论 #14423882 未加载
评论 #14414797 未加载
ericfrederichabout 8 years ago
I like to run gource: <a href="http:&#x2F;&#x2F;gource.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;gource.io&#x2F;</a>
评论 #14409740 未加载
评论 #14412040 未加载
Vinnlabout 8 years ago
&gt; You’re not limited to just tags: you can use commit hashes.<p>Since tags, branches and `HEAD` are simply pointers to commits, it&#x27;s good to know that you can interchange them and commits pretty much anywhere where you can use them (other than creating&#x2F;deleting tags or branches, of course).
评论 #14429211 未加载
falcolasabout 8 years ago
I&#x27;ll be adding a lot of these; I especially like the &quot;what was I doing...&quot; ones. To continue with the sharing:<p><pre><code> up = !git pull --prune $@ &amp;&amp; git submodule update --recursive cm = !git add -A &amp;&amp; git commit save = !git add -A &amp;&amp; git commit -m &#x27;SAVEPOINT&#x27; undo = reset HEAD~1 --mixed amend = commit -a --amend # Removes branches deleted from remote repo bclean = &quot;!f() { git branch --merged ${1-master} | grep -v &quot; ${1-master}$&quot; | xargs git branch -d; }; f&quot; # Leave current branch &amp; do some cleanup bdone = &quot;!f() { git checkout ${1-master} &amp;&amp; git up &amp;&amp; git bclean ${1-master}; }; f&quot;</code></pre>
评论 #14410370 未加载
patrick_haplyabout 8 years ago
Out of curiosity, does anyone here use tig[1]? I&#x27;ve been wondering if it&#x27;s worth learning.<p>[1] <a href="https:&#x2F;&#x2F;jonas.github.io&#x2F;tig&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jonas.github.io&#x2F;tig&#x2F;</a>
评论 #14415358 未加载
gumbyabout 8 years ago
It&#x27;s annoying that all the git commands start with &#x27;git&#x27; unless you write your own aliases. It means you can&#x27;t just type !sta to get the git status much less &#x27;emacs !add:*&#x27; to edit the files you just added(!) ; you have to do a ^R search and edit. !git is almost never what you want unless it&#x27;s just !! anyway. RCS had just co and ci and the like[+]<p>Clearly the guy who came up with this cockamamie scheme was unfamiliar with Linux. :-)<p>+ RCS was pretty bad too; I&#x27;m using it just for illustrative purposes
macraelabout 8 years ago
Something I love to do with git: make temporary commits at the tip of a branch so I can checkout other branches without losing anything. I much prefer this to stashes, generally. Stashes can still be useful to move changes from one branch to another, but generally I find changes make sense on the branch they were being written for.<p>&gt; git commit -am &quot;TMP COMMIT&quot; &gt; git checkout ... Once you switch back: &gt; git reset HEAD^<p>and you&#x27;ll undo the temporary commit and be back to where you were.
评论 #14414402 未加载
评论 #14416040 未加载
atemerevabout 8 years ago
And the question is... why all these nice features are not enabled by default? Especially word-level and whitespace-aware diffs.
评论 #14409945 未加载
roel_vabout 8 years ago
So how do largish binaries work in git nowadays? When I last looked (several years ago), the answer was essentially &#x27;dont do it&#x27; or &#x27;use this other tool to sort of make it work&#x27;. Can I store a few gigs of data (alongside my source code) in git?
评论 #14411035 未加载
评论 #14411389 未加载
nitemiceabout 8 years ago
I actually have that leaderboard alias in my gitconfig already.<p>I work on a codebase that&#x27;s over 20 yrs old. A while back, I was interested to find out who had done the most commits, and what kind impact moving to git, with it&#x27;s &quot;commit early, commit often&quot; mentality, had pushed newer players up the ranks. Suffice to say, it hadn&#x27;t had as much impact as I was expecting yet.
linkmotifabout 8 years ago
I&#x27;ve always thought of git blame as a bit of Linus personality infusion into the git CLI. Aliasing that to &quot;praise&quot; kind of misses that bit of fun.
评论 #14414348 未加载
herrvogel-about 8 years ago
Git-extras[0] is also quite nice.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;tj&#x2F;git-extras" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tj&#x2F;git-extras</a>
jordighabout 8 years ago
There&#x27;s a great comparison with hg here:<p><a href="https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;f0t07t&#x2F;little_things_i_like_do_with_git#c_hbus14" rel="nofollow">https:&#x2F;&#x2F;lobste.rs&#x2F;s&#x2F;f0t07t&#x2F;little_things_i_like_do_with_git#...</a>
hyperpalliumabout 8 years ago
Instead of --word-diff, I like --color-words.<p>Though it can be difficult to notice an addition if it&#x27;s just one or two chars.
soperjabout 8 years ago
I use meld as my git diff tool. Visual diff is just way easier in my opinion.
mmjaaabout 8 years ago
My personal favourite:<p><pre><code> git for-each-ref --sort=-committerdate </code></pre> .. shows progress for each branch .. this makes it surprisingly easy to see which of the developers in our group (with their own branches) is pushing the codebase further ..
评论 #14410015 未加载
评论 #14411449 未加载
评论 #14410239 未加载
cryptonectorabout 8 years ago
This is why I wish Fossil were less opinionated and supported rebase and exposed branches and tags as the light-weight names that they are underneath the covers (just like git). Fossil uses SQL, which means that all of the things @csswizardry and much more that no git developer has ever thought of.. can be done with a little bit of SQL.<p>But no, Fossil&#x27;s UI is like Mercurial&#x27;s, and it favors merging over cherry-picking and rebasing. Their loss!<p>Fossil does have a cherry-pick operation, and anyways, one could trivially be constructed. Which means that rebase can also be constructed easily enough. But my impression is that the devs aren&#x27;t interested in such contributions. And the heavy- vs. light-weight branching model in the UI is a big turn off even if I can deal with it at the SQL level. Fossil&#x27;s push&#x2F;pull model ([auto]sync everything) is also not to my liking -- sure, in a corporate environment pushing every branch is a good idea, but in an open source world it&#x27;s not: I may want to push some branches to one upstream, others to another, and yet others not at all.<p>This is what I like about git:<p>- the index<p>- git exposes the Merkle hash tree concept at the lowest layer<p>- git branches and tags are just symbolic pointers to commits (see previous point)<p>- support for many remotes<p>- git is not opinionated -- if you want to use a merge-based workflow, you can, and if you want to rebase instead, you can, and if you have to use e-mail to exchange commits, you can, and so on.<p>I&#x27;m done with the Mercurial &quot;you do what we say&quot; model. A model they keep half-way reneging on, adding bookmarks (which don&#x27;t work well), and histedit and rebase (why not both in one command?! &quot;because we don&#x27;t like git rebase&quot; is the answer I imagine) (they really need to be one command!! what if in the process of rebasing you must drop commits that you know duplicate others in the new base?!).<p>I wish Fossil&#x27;s developers saw this. But they&#x27;re focused on their needs: VCS for SQLite3. Since they seem to have few topic branches, they like merging.<p>Conversely, since Fossil&#x27;s devs refuse to be non-opinionated, I wish git&#x27;s developers saw the power of SQL for VCS. It would save a ton of code C and shell code, and it would make new extensions trivial. It also would make git much more power-failure safe: since it could leave that to something like SQLite3 that does a fantastic job of it (and is very well tested, both in general and as to power failure safety).<p>Besides this, I wish git has branch history. That is, a single push can push multiple commits by different authors, so it would be nice if one could see who pushed what commits. This would be useful as documentation in and of itself: if you see N&gt;1 commits pushed together and need to revert one of them, you might look at whether you need to revert the rest as well, as they might go together. (Some codebases like to push regression tests first, bug fixes after. This allows one to see that tests detect the bugs they&#x27;re testing for and that corresponding bug fixes fix those bugs. If one has to revert a bug fix commit, one might have to also revert a corresponding test commit.)
评论 #14411608 未加载
评论 #14413607 未加载