Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git将添加、提交和推送命令集于一身?_Git - Fatal编程技术网

git将添加、提交和推送命令集于一身?

git将添加、提交和推送命令集于一身?,git,Git,有没有办法一次使用这三个命令 git add . git commit -a -m "commit" (do not need commit message either) git push 有时我只改变一个字母,CSS填充或其他。尽管如此,我还是必须编写所有三个命令来推动更改。有很多项目我只是一个推动者,所以这个命令会很棒 我认为您可能误解了git设计的工作流程。(为了澄清/纠正我在评论中的意思,您不需要使用git add.,因为commit-a通常用于相同的目的-添加任何尚未暂存的更改(如

有没有办法一次使用这三个命令

git add .
git commit -a -m "commit" (do not need commit message either)
git push

有时我只改变一个字母,CSS填充或其他。尽管如此,我还是必须编写所有三个命令来推动更改。有很多项目我只是一个推动者,所以这个命令会很棒

我认为您可能误解了git设计的工作流程。(为了澄清/纠正我在评论中的意思,您不需要使用
git add.
,因为
commit-a
通常用于相同的目的-添加任何尚未暂存的更改(如果已经添加了文件)

通常,您将执行以下操作:

# make some changes
$ git commit -a -m "Changed something"
# make some more changes
$ git commit -a -m "Changed something else"
清洗、冲洗、重复,直到您完成功能X,或者您处于停止点,或者您只是想让其他人看到您所做的。那你呢

$ git push

Git不是SVN——但看起来您正试图使用它。您可能会发现本文末尾的一些参考资料有些用处。

虽然我同意Wayne Werner的质疑,但从技术上讲,这是一种选择:

git config alias.acp '! git commit -a -m "commit" && git push'
它定义了一个运行
commit
push
的别名。将其用作git acp。请注意,此类“shell”别名总是从git存储库的根运行

另一种选择可能是编写一个执行推送的post-commit钩子

哦,顺便说一下,您确实可以将参数传递给shell别名。如果要传递自定义提交消息,请改用:

git config alias.acp '! acp() { git commit -a -m "$1" && git push ; } ; acp'

(当然,现在,您需要给出一条提交消息:
git acp“我的消息在这里!”

如果文件已经被跟踪,那么您不需要运行
git add
,只需编写
git commit-am'your message'

如果你不想写提交消息,你可以考虑做一些类似

的事情。
git commit--允许空消息-am'
在bash中设置为别名:

$ alias lazygit="git add .; git commit -a -m '...'; git push;";
叫它:

$ lazygit

(要使此别名永久化,您必须将其包含在.bashrc或.bash_配置文件中)

基于@Gavin的答案:

使lazygit成为一个函数而不是别名允许您向它传递一个参数。我已将以下内容添加到我的.bashrc(或.bash_配置文件,如果是Mac):

这允许您提供提交消息,例如

lazygit "My commit msg"

当然,您可以通过接受更多的参数来加强这一点,例如推到哪个远程位置,或者推到哪个分支

您可以使用bash脚本,设置alias来启动任何命令或命令组

git commit -am "your message" && git push 
如回答中所述,您可以创建一个git别名,并为其分配一组命令。在这种情况下,它将是:

git config --global alias.add-com-push '!git add . && git commit -a -m "commit" && git push'
和它一起使用

git add-com-push

上述脚本存在一些问题:

shift“删除”参数$1,否则,“push”将读取并“误解”

我的建议:

git config--global alias.acpp'!git add-A&&branchatu=“$(git 符号参考头2>/dev/null)&&branchatu=${branchatu##参考头/heads/} &&git commit-m“$1”&&shift&&git pull-u origin$branchatu&&git 推送-u原点$branchatu'


我在我的.bash_配置文件中使用它

gitpush() {
    git add .
    git commit -m "$*"
    git push
}
alias gp=gitpush
它执行起来就像

gp A really long commit message

保存别名后,别忘了运行
source~/.bash\u profile

我最后在我的
.gitconfig
文件中添加了一个别名:

[alias]
    cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
用法:
git-cmp“长提交消息出现在这里”

添加所有文件,然后对提交消息使用注释并将其推送到源

我认为这是一个更好的解决方案,因为您可以控制提交消息的内容

还可以从命令行定义别名,这会将其添加到
.gitconfig

git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'
我使用批处理文件:

@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push

当您希望git提交具有类似svn的行为时,请在.gitconfig中的git别名中使用它

commit=“!f(){git commit\“$@\”和&git push;};f”

您可以尝试

第一次(必须安装node js):

之后:

gitu COMMIT_MSG
同时发出这三个命令

好消息是,当您重新安装系统时,或者当您想在不同的计算机上执行此操作时,您不必担心,而且不需要修改文件。
这同样适用于不同的平台(不仅仅是Linux和Mac,还有Windows下的命令提示符,比如
cmd
powershell
),只是你必须安装
npm
nodejs
git

#!/bin/sh
cd LOCALDIRECTORYNAME/  
git config --global user.email "YOURMAILADDRESS"
git config --global user.name "YOURUSERNAME"
git init
git status
git add -A && git commit -m "MASSAGEFORCOMMITS"
git push origin master

因为这个问题没有指定哪个shell,下面是基于前面答案的eshell版本。这在eshell别名文件中,可能在~/.emacs.d/eshell/alias中。我添加了第一部分z,让您可以快速将cd刻录到目录中,这样无论当前目录是什么,都可以运行它

alias census z cens; git add .; git commit -m "fast"; git push

在Linux/Mac中,这个非常实用的选项也应该起作用

git commit -am "IssueNumberIAmWorkingOn --hit Enter key
> A detail here --Enter
> Another detail here --Enter
> Third line here" && git push --last Enter and it will be there
如果您正在处理本地创建的新的分支,请使用
git push-u origin branch\u name

如果要在系统编辑器中编辑提交消息,则

git commit -a && git push 

将打开编辑器,保存消息后,它也将推送消息

外接程序
~/.bash_profile
用于通过一个命令put添加、提交和推送:

function g() { git commit -a -m "$*"; git push; }
用法:

g your commit message
g your commit message 'message'
p
虽然不能在提交消息中使用分号或括号,但不需要引号(允许使用单引号)。如果您想查看其中任何一条,只需在邮件中加上双引号即可,例如:

g "your commit message; (message)"
要在邮件中创建注释,请执行以下操作:

g "your commit message:
> your note"
还有一个用于以类似方式添加和提交的函数:

function c() { git add --all; git commit -m "$*"; }
g
函数的工作方式完全相同,并且具有相同的约束条件。只要把
c
放进去就行了。 例如

您还可以添加用于推送到远程的别名:

alias p='git push'
用法:

g your commit message
g your commit message 'message'
p
总共有两个字母,
c
p
,您在w
p
### SAFER LAZY GIT
function lazygit() {
  git add .
  if git commit -a -m "$1"; then
    read -r -p "Are you sure you want to push these changes? [y/N]} " response
    case "$response" in
      [yY][eE][sS]|[yY])
        git push
        ;;
      *)
        git reset HEAD~1 --soft
        echo "Reverted changes."
        ;;
    esac
  fi
}
function quickgit # This is the function name and command we call
    git --git-dir=$PWD/.git add . # Stage all unstaged files
    git --git-dir=$PWD/.git commit -a -m $argv # Commit files with the given argument as the commit message
    git --git-dir=$PWD/.git push # Push to remote
end
legit(){ git add --all; git commit -m "$1"; git push origin master; }
legit 'your commit message here'
git commit -a -m "commit" && git push
git add . && git commit -a -m "commit" && git push
#!/bin/bash
git commit "$@" && git push -u
echo $1
git add .
git commit -m "$1"
git push
alias gitpush='~/gitpush'
git commit -am "message";git push
Shell Command: install 'code' command in PATH
function lazygit() {
    git add .
    git commit -m "$*"
    git push
}
function lazygit() {
    git add .
    git commit -a -m "$1"
    git push
}
lazygit "This is my commit message"
function lazygit() {
    git add .
    git commit -a -m "$1"
    git push
}