1

I want to have a new git alias with which I can checkout file(s) from an older revision under new file name(s).

I have a git alias for showing log saved in my C:\Users\nguyen\.gitconfig

[user]
name = Tin Nguyen
email = xx@xx.com

[diff]
tool = winmerge

[difftool "winmerge"]
cmd = "'C:/Program Files (x86)/WinMerge/WinMergeU.exe'" -e "$LOCAL" "$REMOTE"

[alias]
    alog = log --all --decorate --oneline --graph

I tried to apply what I had with difftool but somehow I kept getting the syntax wrong.

Here a question was answered how to git checkout a file under a new file name: git-checkout older revision of a file under a new name

git show 4c274dd91dc:higgs/Higgs.xcodeproj/project.pbxproj > old_project.pbxproj
prompt> 

I want to be able to write:

git smartout 4c274dd91dc oldname.py as newname.py
Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32
  • I very much doubt any alias will be shorter or simpler than the `git show` command. – phd Jul 04 '19 at 15:09

1 Answers1

0
git config --global alias.smartout '!f() { !git show $1:$3 > $2; }; f'

then

git smartout 4c274dd91dc fullpath/to/oldname.py fullpath/to/newname.py

(As a sidenote, mind the small word "as" which I stripped from your desired format, because it was bringing a lot of trouble, for the only "benefit" of making each use a bit longer to type. phd's doubts about the alias' usefulness would be even more accurate with an additional word here.)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61