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

4
  • 2
    You're talking about Bash aliases? Why not just make a function? Commented Jul 5, 2014 at 18:43
  • 1
    Are you using git-bash under Windows? Or cmd.exe? Commented Jul 5, 2014 at 18:51
  • @merlin2011: I'm using git-bash Commented Jul 5, 2014 at 19:16
  • I believe the answer should work for you under git bash but I cannot test it because I currently don't have access to a windows system. Commented Jul 5, 2014 at 20:29

2 Answers 2

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" 
Sign up to request clarification or add additional context in comments.

3 Comments

You need to put this function in .bashrc (or if you using zsh in .zshrc). After recreating a terminal the function is available.
@Celt0, Good point. I thought that was implied but you are right that I should make it explicit.
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.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.