LoginSignup
1
1

More than 5 years have passed since last update.

Gitでn番目のコミットハッシュを取得するワンライナー

Last updated at Posted at 2012-01-18

cherry-pickを使う際のお供に.
gitpythonが使えるなら素直にそっちを使った方がよいかも.
そもそもPythonで書く意味はあまりない…

python -c "n = 1; import re ;from subprocess import Popen, PIPE;import sys; sys.stdout.write([commit.split(' ')[1] for commit in re.split('\n*', Popen(['git', 'log'], stdout=PIPE).communicate()[0]) if commit.startswith('commit ')][n])" | pbcopy

(追記) subprocessモジュールを使わないでsys.stdinを使用したバージョン.こっちの方がまだ少しは書きやすい.

git log | python -c "import sys; word = 'commit '; n = 0; p = lambda x: sys.stdout.write(x); l = [line.replace(word, '') for line in sys.stdin if line.startswith(word)]; p(l[n])" | pbcopy
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1