Skip to content

Instantly share code, notes, and snippets.

@korny
Created January 8, 2015 10:03
Show Gist options
  • Save korny/779253995464f1205620 to your computer and use it in GitHub Desktop.
Save korny/779253995464f1205620 to your computer and use it in GitHub Desktop.
Copy a file's master version to your working directory (prefixed with old_)
#!/usr/bin/env ruby
source = ARGV.first or raise 'need a file name'
basename = File.basename(source)
target = File.join File.dirname(source), (basename[/^_/] ? '_old' : 'old_') + basename
exec "git show master:#{source} > #{target}"
@korny
Copy link
Author

korny commented Jan 8, 2015

Sometimes, you want to have the old and the new version of a file in your editor. Switching between branches can be tedious, and diffs are hard to work with when you want to copy parts of the old code over.

With this, you have both files available at the same time. Just remove the old_file when you're done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment