Git

git foo

A few git commands I find myself having to look up:

Resolve Git merge conflicts in favor of their changes during a pull:

git pull -Xtheirs
git checkout --theirs the/conflicted.file

Source

Viewing Unpushed Git Commits

git log origin/master..HEAD

You can also view the diff using the same syntax:

git diff origin/master..HEAD

Or, “for a little extra awesomeness”

git log --stat origin/master..HEAD 

Updated since it was first posted:

Starting with Git 2.5+ (Q2 2015), the actual answer would be git log @{push}… See that new shortcut @{push}

And:

Outgoing changes: git log @{u}.. Incoming changes: git log ..@{u}

@{u} or @{upstream} means the upstream branch of the current branch (see git rev-parse --help or git help revisions for details).

SVN or git?

@film_firl poked @WordPressVIP to ask @wordpressvip @mjangda @viper007bond MOOOOVE TO GIT!!! she half-kids. No really, please? — Christina Warren (@film_girl) January 18, 2013 @nacin piled on with @viper007bond @film_girl @mjangda VIP aside, it’s fairly crazy that WordPress.com hasn’t migrated. SVN != tenable dev environment. — Andrew Nacin (@nacin) January 18, 2013 @Viper007Bond tried to defend the team, and […] » about 300 words

There’s no ‘git cp filename’?

Here’s a sequence of unbelievable things:

  1. Yes, despite a lifetime in Subversion, I’m really this new to git!
  2. I’m going to link to Livejournal in this post!
  3. Git really doesn’t have an equivalent to svn cp filename!

I spent a surprisingly long time reviewing the man pages and surfing the internet to confirm this, but git really assumes you’ll never want to copy a file with history. Here’s that Livejournal link I promised, where markpasc has similar complaints — from 2008, no less.

I was looking for a way to copy a file with history because I needed to break a single file into multiple pieces. In my Subversion days I would have done a svn cp old-file.php new-file.php. From there I could prune old-file.php and new-file.php down to what I needed while preserving the full history for all the code that remained.

Or perhaps I’m missing something?