git命令批处理bat文件

来源:互联网 发布:c语言逻辑表达式 编辑:程序博客网 时间:2024/06/06 05:21
Git装好后有个cmd目录,把这个路径加到Windows的path环境变量下,然后像平时写bat批处理文件一样,把git命令写到里边去就行了。不用再做bash的login操作。
此时脚本中执行其他的dos命令和第三方命令行程序均不受影响。
我的cmd目录是在:E:\Program Files (x86)\Git\cmd

然后就可以新建一个bat文件,在里面写需要做的操作。
例如:
echo .....Jump to folder E:\komi\komiTest(跳转至该路径,是一个git项目,应该会有一个.git文件夹。如果这个bat文件已经在git项目路径下了,可以不用跳转,直接写git命令,会对该git项目直接进行操作)cd /d E:\komi\komiTestecho .....!!!!git checkout master (执行git命令:切换至master分支)git checkout masterecho .....enter any key to exit(想要bat文件执行完可以看到日志,而不是自动关闭,用以下方式可以实现:pause>nul)pause>nul
然后执行这个bat文件,就可以看到git开始按命令进行各种操作啦~

注意:
使用git bash命令有一个错误警告:
warning: push.default is unset; its implicit value is changing inGit 2.0 from 'matching' to 'simple'. To squelch this messageand maintain the current behavior after the default changes, use:git config --global push.default matchingTo squelch this message and adopt the new behavior now, use:git config --global push.default simple
解决:事实上这并不会影响你push的结果,最终push还会成功,因为这只是一个”warning“。
只要在git bash运行:git config --global push.default matching或者git config --global push.default simple命令,以后再push就不会有警告了。

下面说一下push.default matchingpush.default simple的区别:
push.default设置maching的意思是:git push 会把你本地所有分支push到名称相对应的远程主机上。这意味着可能你会在不经意间push一些你原本没打算push的分支。
push.default设置成simple的意思是:git push仅仅把当前所在分支push到从当初git pull pull下来的那个对应分支上,另外,这个过程也会同时检查各个分支的名称是否相对应。