git 批处理bat管理常用命令

@echo off
rem 进入git的项目根目录...
cd E:\WebSite\
set gitcmd="D:\Program Files\Git\git-cmd.exe"
set num=5
echo 【【【【【输出最近%num%次提交,如果不自动退出,按q退出】】】】】
echo 【【【【【输出最近%num%次提交,如果不自动退出,按q退出】】】】】
echo 【【【【【输出最近%num%次提交,如果不自动退出,按q退出】】】】】
echo.
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git log --oneline -%num%"

:start
echo.
echo. ******************************************************************************
echo. 使用 完整/短的 commit id 都可以,如果使用短的commit id出错请使用完整的
echo                1.打包某次更新提交
echo                2.打包两个更新之间的提交
echo                3.打包最新提交和本地未提交的修改
echo                4.拉取最新代码下来
echo                5.中文错误修复
echo                6.提交本地修改代码
echo                7.查看本地更新
echo                8.查看更新记录
echo                9.进入git bash
echo. ******************************************************************************

set /P type="请输入(1/2/3),默认 1:"
if "%type%" == ""  goto a
if "%type%" == "1" goto a
if "%type%" == "2" goto a
if "%type%" == "3" goto c
if "%type%" == "4" goto d
if "%type%" == "5" goto e
if "%type%" == "6" goto f
if "%type%" == "7" goto g
if "%type%" == "8" goto h
if "%type%" == "9" goto i
goto start

:a
set /P new_id="Please input NEW_COMMIT_ID_HERE:"
echo        new_id:%new_id%
if "%new_id%" == "" goto a
if "%type%" == "2" goto b

%gitcmd% --command=usr/bin/bash.exe -l -i -c "git archive -o NDupdate.zip %new_id% $(git diff-tree -r --no-commit-id --name-only %new_id%)"
goto exit

:b
set /P old_id="Please input OLD_COMMIT_ID_HERE:"
echo        old_id:%old_id%

if "%old_id%" == "" goto c

rem 打包...
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git archive -o NDupdate.zip %new_id% $(git diff --name-only %old_id% %new_id%)"
goto exit


:c
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git archive -o NDupdate.zip HEAD $(git diff --name-only HEAD^)"
goto exit

:d
git pull
goto exit

:e
git config --global core.quotepath false
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git config --global core.quotepath false"
echo.    修复完毕
goto start

:f
set /p  fo=  请输入要上传的文件名,开始上传输入1,返回上级输入0:
if "%fo%" == "1" goto ff
if "%fo%" == "0" goto start
git add "%fo%"
goto f

:ff
echo 正在进行提交中...
set /p  co=  请输入描述内容:
echo 正在进行对文件进行描述中...
git commit -m "%co%"
git push origin master
echo git文件上传完成...
goto start

:g
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git checkout"
goto start

:h
%gitcmd% --command=usr/bin/bash.exe -l -i -c "git log --oneline -%num%"
goto start

:i
%gitcmd% --command=usr/bin/bash.exe -l -i 


:exit

rem 退出 
pause
exit;


-----------------------------------------------------------------
---------------------华丽的分割线--------------------------------
-----------------------------------------------------------------

【杂乱笔记,看官可忽略:】

打包某个提交的版本所有代码、
set /P new_id="input new md5(NEW_COMMIT_ID_HERE):"
if "%new_id%" == "" goto B
git archive --format zip --output NDupdate.zip %new_id%

liunx:
git diff-tree -r --no-commit-id --name-only 6e9322a39381fea103bd69b62040dc4c4fde3008 | xargs zip -rf mytarfile.zip


这个命令也行:
"D:\Program Files\Git\usr\bin\bash.exe" --login -i -c "'D:\Program Files\Git\cmd\git.exe' archive -o NDupdate.zip 937ee74d836537a6969b3a47487c2df011c33117 $('D:\Program Files\Git\cmd\git.exe' diff --name-only 4c294b57ee953250520588f083f62e926b7b476b 937ee74d836537a6969b3a47487c2df011c33117)"

start "" "D:\Program Files\Git\git-bash.exe" -c "echo 1 && echo 2 && /usr/bin/bash --login -i -c 'git archive -o NDupdate.zip 937ee74d836537a6969b3a47487c2df011c33117 $(git diff --name-only 4c294b57ee953250520588f083f62e926b7b476b 937ee74d836537a6969b3a47487c2df011c33117')"

quit

rem set /P input="输入要在git-bash中打开的项目路径:"
rem start D:\Program" "Files\Git\git-bash.exe --cd=%input% --command="/usr/bin/bash --login -i"


pause

"D:\Program Files\Git\git-bash.exe" --command="usr\\bin\\bash.exe --login -i -c git archive -o NDupdate.zip 64e4642 $(git diff --name-only 7a8947a 64e4642)"


"D:\Program Files\Git\usr\bin\bash.exe" --login -i -c "ls"

"D:\Program Files\Git\git-bash.exe":
--command=<command-line>::
    Executes `<command-line>` instead of the embedded string resource

--[no-]minimal-search-path::
    Ensures that only `/cmd/` is added to the `PATH` instead of
    `/mingw??/bin` and `/usr/bin/`, or not

--[no-]needs-console::
    Ensures that there is a Win32 console associated with the spawned
    process, or not

--[no-]hide::
    Hides the console window, or not

/usr/bin/bash: --: invalid option
Usage:  /usr/bin/bash [GNU long option] [option] ...
        /usr/bin/bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -ilrsD or -c command or -O shopt_option         (invocation only)
        -abefhkmnptuvxBCHP or -o option

其他参考:http://blog.51cto.com/13717297/2136859

发布了69 篇原创文章 · 获赞 31 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/yyws2039725/article/details/103308611