16

我有以下按相应顺序运行的命令列表,以便可以提交源项目并将其推送到 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

现在不是将每一行放在各自的时间和顺序上,我想知道,是否有可能我可以将所有这些链接到一个git命令中并保持相同的顺序,如下所示?

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

或者至少组合多个相同类别的参数,如下所示?

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

我需要通过示例了解这两种情况的可能性。

4

3 回答 3

30

We can use list off command in single command for example:

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
于 2018-02-16T02:10:28.217 回答
5

如果您在 Windows shell 中:

git add . ; git commit -m "Testing one line command" ; git push
于 2019-10-15T14:18:10.933 回答
1

我在 Windows 系统上有 gitbash,我对 Win 批处理的使用不如 Linux shell 好。

您仍然可以编写 bash 脚本(由嵌入Git for Windows的msys2 bash解释)。 正如Lasse V. Karlsen的评论中提到的,以及我之前在“哪个 shell 用于 git '!”中提到的那样 别名? ”,您可以在名为 的文件(在您的 %PATH% 中)中编写一个 shell 脚本,并使用. 该脚本将从以下内容开始:
git-xxxgit xxx

#!/bin/bash
于 2017-05-06T21:36:04.177 回答