I view my git logs in CMD which has a custom format,
git log --date=format:'%d %b %I:%M%p' --pretty=format:"%C(Yellow)%h%Creset %cd%Cgreen%d %Creset%s" -10
now I have to copy this command every time from my notepad so I was thinking if I can create a custom cmd command that will run the above command.
for eg. I would just write
showlog
and it will execute my command.
I tried creating a bat file and found this command.
start cmd.exe #cmd /k "git log --oneline -10"
but it opened a new window I would like this to execute in the same window like other git commands
So I want to know
how exactly it is done within the same window?
where can I learn more about this?
You don't have to use start nor cmd in your batch file, just the command itself:
#echo off
my command and parameters here
so for your showlog.bat:
#echo off
git log --date=format:'%d %b %I:%M%p' --pretty=format:"%C(Yellow)%h%Creset %cd%Cgreen%d %Creset%s" -10
% might be problematic, you might have to escape it with %%. While debugging you can remove the #echo off to have it echo the command...
Instead of (correct) #anders way for custom cmd-command, you can think about more Git-way of building Git alias (use git showlog) for the same output: simple, (somehow) faster and more manageable solution.
Something like
git config --global alias.showlog 'git log <FULL TAIL OF YOUR COMMAND HERE>'
Related
You can do
start powershell -command ls
to open PowerShell and get it to list files. I'm trying to do a similar thing with Git Shell. Currently I have
%LOCALAPPDATA\GitHub\Github.appref-ms --open-shell -command ls
which opens Git Shell, but doesn't do anything else. Is it possible to run a command after starting Git Shell in this way?
Since this hasn't been answered I'm going to offer an alternative solution of using git-bash instead of the MS application reference file.
start /b cmd /c "C:/Program Files/Git/git-bash.exe" /C/path/to/script.sh
See this question: Cant run shell script using Git Bash interface on Windows10
In Windows I can run "Git Bash Here" in the current directory by opening right click menu.
I want to place gitbashhere.bat in default path for commands to have got easy access from standard cmd window.
The sh.exe --login -i command only opens git bash in sh.exe's directory instead of the current directory.
How do I check what command is bound to "Git Bash Here"?
How do I check what command is bound to "Git Bash Here"?
Open the Registry Editor using regedt32 or regedit.
Menu "Edit" > "Find" > "Find what" and enter "git_shell"
Examine the returned Registry entries.
One will be:
HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
With the value:
"C:\Windows\SysWOW64\cmd.exe" /c "pushd "%1" && "C:\git_install_dir\bin\sh.exe" --login -i"
where git_install_dir is the directory where you have installed git.
You can see it runs something similar to the following command:
pushd "%1" && "C:\git_install_dir\bin\sh.exe" --login -i
Another way to see how a specific program was started is to launch Process Explorer, look for the process in the list of processes (for git this would be "git-bash.exe") and double-click on the process to open the properties.
On the 'Image' tab there's a text field that yields the command line of the process:
That is a windows shell thing. It depends on the git GUI toolkit that you've installed. For tortoiseGit, there's a setting hidden somewhere in the configuration menu. If that doesn't suit you: It's free and open software, so fix that :)
I've seen it in linux. There's a console you can open that is just a shell. I want the same thing in windows only with either cmd, or with git bash. (MINGW32). I tried googling it but just got flooded with articles about egit and normal git bash.
If you have msysgit, you can use it from a regular cmd session:
Launch c:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-cmd.bat, and you can type in that cmd windows regular git commands.
For a bash session: c:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-bash.bat.
Note that you need to modify those bat:
git-cmd.bat: add a rem before the setlocal command, and before the start at the end.
git-bash.bat: add a rem before the setlocal command.
So you can add to your Eclipse an external tool which will open a cmd in your console:
Except, instead of calling C:\windows\system32\cmd.exe (in the "Location" field from the picture above), you could call directly: C:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-bash.bat.
By 'msysgit', I refer to whatever name you gave to the uncompresdsed portable version of "Git For Windows": download it there.
And then you could type git command within the Eclipse console (including a bash session)!
After testing, the color codes get in the way, even if git works:
git-cmd.bat:
git-bash.bat:
I hope to add a Windows Scheduled Task to git push to github every night. I have a CMD file. When I run the CMD file on the windows command prompt, it works fine. But when I run it via windows scheduled task. It's stuck forever. The status is "running". And from the log I can see it successfully started the git bash shell. Any idea?
echo git push > i:\gitpush
echo 'pushing' >>log1
C:\WINDOWS\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login i:\gitpush" >>log1 2>>error
echo 'done pushing' >>log1
del i:\gitpush
Here is the log output:
'pushing'
Welcome to Git (version 1.7.4-preview20110204)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Then I did an experiment to rename gitpush script to a wrong file name. And it exited immediately with the error "No such file or directory", which is expected. It shows the gitpush script is passing in correctly to the bash but for some reason it's stuck.
The reason I have to go through git bash shell is because I don't know how to setup public key in windows command line shell without using git bash shell.
Thanks!
I don't know how to setup public key in windows command line shell
Public/private keys work also in a DOS shell, provided you define the %HOME% environment variable (referencing the parent directory of the .ssh)
The trick with Windows Scheduled Task is to make sure:
who is actually running the task (the "system account"? or the actual user?)
Displaying "env" can help debugging the issue.
where it is run: if git push depends on the current path to properly push the current repo, you need to be certain that your task runs where it is supposed to.
For daily backup of my mercurial repositories on Windows XP I used a simple batch file hg_backup.bat which just did some directory changes and mercurial calls with a pause command in the end like this:
#Z:
#cd \hg_backup\drawings
hg pull -v
#cd \hg_backup\src\scripts
hg pull -v
#cd \hg_backup\eagle4\lbr
hg pull -v
#pause
This worked fine with mercurial up to 1.7 (installed with TortoiseHg). However since mercurial 1.8 it starts the very first mercurial command and then exits abruptly without reaching the following commands or even the end of the script. The command window just disappears.
I had the same problem some time before, when I tried the same thing with git, but didn't investigate further, because I use git for one repository only. It seems to me, there's some return code of the hg command line call involved which causes the script to end instead of executing the other command but I couldn't verify this yet.
Has anyone an idea why this happens or maybe even how to fix it?
If your hg is a hg.bat or hg.cmd, use call hg and see if it starts working.
The command.com shell executes batch files replacing the old script (to save memory), and requires using call to start a batch script and continue execution later. This behavior remains in Windows cmd.exe for compatibility.
I had the exact same problem, but the solution provided by #grawity didn't work for me (and I have no idea why).
The solution in my case was to replace call with cmd /C, like so:
cmd /C hg sum
cmd /C hg stat