One liner to get the nth commit hash in Git

To accompany you when using cherry-pick. If you can use git python, it may be better to use it obediently. It doesn't make much sense to write in Python in the first place ...

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

(Addition) Version using sys.stdin without using subprocess module. This is still a little easier to write.

 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

Recommended Posts

One liner to get the nth commit hash in Git
[Shell] How to get the remote default branch in Git
Get the top nth values in Pandas
Let's parse the git commit log in Python!
One liner to 100% CPU1 core usage in Python
How to get the files in the [Python] folder
Use pygogo to get the log in json.
One liner in Python
How to retrieve the nth largest value in Python
How to get the variable name itself in python
How to get the number of digits in Python
One liner to talk somewhere
Get the package version to register with PyPI from Git
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
How to get all the possible values in a regular expression
Hit the New Relic API in Python to get the server status
How to get the vertex coordinates of a feature in ArcPy
I want to pass the G test in one month Day 1
The easiest way to get started in Slack socket mode (Go)
Create a function to get the contents of the database in Go
Format the Git log and get the committed file name in csv format
Get the IPv4 address assigned to the network interface in code (Linux)
Programming to fight in the world ~ 5-1
Programming to fight in the world 5-3
Get the desktop path in Python
Programming to fight in the world-Chapter 4
Get the script path in Python
In the python command python points to python3.8
How to get the Python version
How to convert 0.5 to 1056964608 in one shot
Get the desktop path in Python
Parsing Git commit logs in Python
Cython to try in the shortest
Get the host name in Python
Programming to fight in the world ~ 5-2
Get the query string (query string) in Django
How to get the date and time difference in seconds with python
Click the Selenium links in order to get the elements of individual pages
[Linux] Command to get a list of commands executed in the past
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Get the client's IP address in Django
Get the path to the systemd unit file
How to get a stacktrace in python
In Jupyter, add IPerl to the kernel.
How to get colored output to the console
I can't get the element in Selenium!
One liner webServer (with CGI) in python
Various comments to write in the program
Get the EDINET code list in Python
I wrote Project Euler 1 in one liner.
How to get people to try out django rest framework features in one file
Use the Java SDK of GoogleMapsAPI to get the result of reverse GeoCoding in Japanese.
How to get the notebook name you are currently using in Google Colab
I want to get the file name, line number, and function name in Python 3.4
Create a filter to get an Access Token in the Graph API (Flask)
How to get a list of files in the same directory with python