简体   繁体   English

在单个命令中执行多个git命令,以便编译器遇到它们

[英]Multiple git commands in single command executed in order they are encountered by compiler

I have following list of commands that I run in respective order so that a source project can be committed and pushed to the repository on Bitbucket: 我有以下按顺序运行的命令列表,以便可以提交源项目并将其推送到Bitbucket上的存储库:

git init
git remote add origin https://[BitBucket Username]@bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git
git config user.name "[BitBucket Username]"
git config user.email "[BitBucket Email ID]"
## if email doesn't work then use below ##
git config --global user.email \<\>
git add *
git commit -m "[Comment]"
git push -u origin master

Now instead of putting each and every line at their respective time and order, I want to know, if there is a possibility that I can chain all these into single git command and maintain the same order, something like below ? 现在,我想知道是否有可能将所有这些都链接到单个git命令中并保持相同的顺序,而不是将每一行分别放在各自的时间和顺序上,如下所示?

git init remote add origin https://[BitBucket Username]@bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git  config user.name "[Username]" ....

Or atleast combine multiple same category params like below ? 还是至少结合以下多个相同类别的参数?

git config user.name "[BitBucket Username]" user.email "[BitBucket Email ID]"

I need to know possibility of both scenarios with examples. 我需要通过示例来了解这两种情况的可能性。

We can use list off command in single command for example: 例如,我们可以在单个命令中使用list off命令:

git add . && git commit -m "updated pom file" && git push

or: 要么:

git stash pop && git add . && git commit -m "updated pom file" && git push
  • && -> if 1st command successfully executes then execute next command else it won't execute next command. && ->如果第一个命令成功执行,则执行下一个命令,否则将不执行下一个命令。
  • & - it executes all the command & -执行所有命令
  • || - execute next command if 1st one failed -如果第一个失败,则执行下一个命令

I have gitbash on Windows system and I am not as good with Win batch as with Linux shell. 我在Windows系统上有gitbash,但Win Batch不如Linux Shell好。

You still can write a bash script (interpreted by the msys2 bash embedded with Git for Windows ). 您仍然可以编写bash脚本(由Windows的Git内嵌的msys2 bash解释)。
As mentioned in the comments by Lasse V. Karlsen , and as I mentioned before in " Which shell used for git '!' 正如Lasse V. Karlsen 的评论中所提到 ,以及我之前在“ 哪个外壳用于git'!”中提到的那样。 aliases? ", you can write a shell script in a file (in your %PATH%) named git-xxx , and call it with git xxx . 别名? ”,您可以在名为git-xxx的文件(在您的%PATH%中)中编写一个shell脚本,并使用git xxx对其进行调用。
That script would begin with: 该脚本将以:

#!/bin/bash

如果您使用的是Windows Shell:

git add . ; git commit -m "Testing one line command" ; git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM