问题
I have the following folder structure...
\GitRepo
\.git
[files]
\IgnoredFolder #ignored from .gitignore
\SubRepo
I'm trying to right a script function in my .gitconfig file and I need to know the current directory, but I'm getting weird behavior.
For all my tests, I've opened a Console2 window hosting Windows PowerShell to run my git commands.
At the prompt if I type $pwd it 'correctly' displays C:\GitRepo\IgnoredFolder\SubRepo. I say 'correctly' but it is in Windows format instead of *Nix.
In my .git config, I've created this alias:
test = "!f() { echo ${PWD}; }; f"
Now, if I type git test from the prompt, I get the 'incorrect' display of /c/GitRepo. I say 'incorrect' because, ignoring Windows vs *Nix format, I would have expected/liked it to return /c/GitRepo/IgnoredFolder/SubRepo.
Other commands behave same way (i.e. operating in the first folder containing a .git repository instead of the current working directory.
For example, the real alias I want to create basically is a shortcut for init, add, commit, remote, config all in one command. A pseudo alias would look like this...
create = "!f() { git init; git add .; git commit -am "$1"; ... anything else ... }; f"
But instead of running on the current directory (the new SubRepo folder I want to 'act on'), it works on the first ancestor folder containing a git repo (c:\GitRepo in this case).
Is there any way to make git alias script functions work on the current directory regardless of whether or not it might be found with in a folder containing a repo or not?
Thanks in advance.
来源:https://stackoverflow.com/questions/23306871/commands-in-a-git-script-functions-windows-not-working-as-expected-in-sub-fold