1

I have to use this command frequently

git difftool head head~2 -- Myefile.cpp.

It is a large command to type all the time. I would like to make an alias of this command with head~n where n is a variable. I want to type

git myfilediff n

where n is an integer number.

How can I do it in windows 10?

Tim
  • 5,435
  • 7
  • 42
  • 62
masiboo
  • 4,537
  • 9
  • 75
  • 136

1 Answers1

1

A quick and dirty solution, to define a bash function in ~/.bashrc if you are using Ubuntu or git-bash-for-windows:

function mfd() {
    git diff HEAD HEAD~${1} -- Myfile.cpp
}

source ~/.bashrc and then mfd 2 is equivalent to git diff HEAD HEAD~2 -- Myfile.cpp.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • 1
    Why is it a "dirty" solution ? – Flows Dec 05 '17 at 10:57
  • @Flows not robust, like a draft. – ElpieKay Dec 05 '17 at 10:59
  • I am in windows 10. I made a file named .bashrc under c:\Users\ma. ma is my username. I put this function. Later tried in git bash. It does nothing. No error output. Also I put it inside .gitconfig. It throws error in git bash. – masiboo Dec 06 '17 at 16:00
  • @masiboo Run `git-bash.exe` and edit `~/.bashrc`. After that, run `source ~/.bashrc` or re-open `git-bash.exe` – ElpieKay Dec 07 '17 at 02:54