Here’s a quick hack that I thought I’d share.
After accidentally pushing some extra commits that were on my local ‘master’ branch, Lars told me that he always tries to do a ‘git push –dry-run’ before pushing, followed by a ‘git log’ in order to check if the reported range is what he was actually intending to push.
After using –dry-run a couple of times and finding that I didn’t particularly care for the manual approach, I wrote a script called “git-wwpd”.
Here it is, in hopes that others will find it to be useful:
#!/usr/bin/env python2 # git-wwpd (what would push do?) import subprocess import sys dryrun = subprocess.Popen(['git', 'push', '--dry-run', '--porcelain'] + sys.argv[1:], stdout=subprocess.PIPE) for line in dryrun.stdout: line = line.rstrip() parts = line.split('\t') if len(parts) == 3 and '..' in parts[2]: print('=== Would update {ref} with range {revs}'.format(ref=parts[1], revs=parts[2])) subprocess.check_call(['git', 'log', '--oneline', parts[2]]) else: print(line)
It ends up looking like this:
desrt@humber:~/code/glib$ git wwpd origin master To ssh://git.gnome.org/git/glib === Would update refs/heads/master:refs/heads/master with range 7417198..7d1d073 7d1d073 Doc: gio: enable gtkdoc-check 7242b7c Doc: glib: enable gtkdoc-check 2ef8ca5 Doc: gobject: enable gtkdoc-check 8446a00 configure.ac: Add ENABLE_GTK_DOC_CHECK conditional 30af941 Doc: gio: Fix all undocumented/unused/undeclared symbols ed34c13 Doc: gobject: Fix all undocumented/unused/undeclared symbols c6e0feb Doc: Fix GListModel/GListStore b14f342 Win32: Move g_win32_check_windows_version() to the correct place in header Done desrt@humber:~/code/glib$
Hey
I found that it’s best not to push to trunk/master anything at all. Push to a code review system and let others review your work. Personally I always read my patches with tig(1) to look for simple mistakes / typos / etc.
Best regards
ZK
Sounds a bit over-engineered to me… I tend to use tig which shows tags/branches in the log which makes it obvious what a push will do, and I also have a llog alias with is basically log –decorate for the same thing.
Also, never work in master, always work in feature branches :)
I have this alias on my ~/.gitconfig:
fulllog = log –graph –decorate –pretty=oneline –abbrev-commit –all
With this a full featured tree showing with colors and what not, is the full history of your repository, so really easy to see what are you about to push
Brought a smile to my face – I only ever made two commits to git itself, and one of them was …
https://github.com/git/git/commit/11f2441f05ace25f1dae833a804761f1ca7d5cbb
Glad that’s still useful ;)
[WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.
Mercurial has a neat feature in the form of two commands: incoming and outgoing. I implemented them as aliases. I have this in my .gitconfig:
[alias]
incoming = !git fetch && git log –oneline ..@{u}
outgoing = log @{u}..
The difference with Mercurial is that git still has to download the objects with fetch while with Mercurial you get just the info you need from the server.