2

In order to see what files I modified in the last period of time I use the following command:

git log --pretty=format: --name-only --since="2 days ago" | sort | uniq

The thing is that I'll like to transform this into an alias. Can I pass the 2 days ago as an argument to my alias command?

PS: I'm using Windows

ctp
  • 93
  • 1
  • 7

2 Answers2

3

If you really want a git alias for some reason, this answer may help you.

However, as Oli's comment mentions, your problem is possibly better solved using a bash function since you are invoking external shell commands anyways. This function definition should be placed in your .bashrc so that it is defined every time you load a shell.

glog() {
   git log --pretty=format: --name-only --since="$1" | sort | uniq
}

Invoke it on the shell like this:

glog "2 days ago"
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • You need to put this function in .bashrc (or if you using zsh in .zshrc). After recreating a terminal the function is available. – Aruscher Jul 05 '14 at 18:49
  • @Celt0, Good point. I thought that was implied but you are right that I should make it explicit. – merlin2011 Jul 05 '14 at 18:50
  • You can also create a real Git alias out of this if you want by prefixing the command with a `!`, e.g. `git config alias.mylog '!git log --pretty=format: --name-only --since="2 days ago" | sort | uniq'`. Now `git mylog` will run that string as a shell command. – ChrisGPT was on strike Jul 05 '14 at 21:23
0

Of course you can create the desired alias. I suggest to read this articel (it alos have link to many usefull aliases)

http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/

The artilce will show you how to write simple aliases along with some advanced git function as aliases.

Good luck.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167