无法使用git commit推送到forked repo并使用脚本推送

时间:2018-02-08 04:34:53

标签: git github git-commit git-push

我已经在GitHub上分叉了一个存储库,并将分叉的存储库克隆到我的本地,并使用 .git/config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = git@github.com:namannigam/commons-io.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "upstream"]
        url = git@github.com:apache/commons-io.git
        fetch = +refs/heads/*:refs/remotes/upstream/*

现在我已经制定了一个脚本(为了问题的可读性而缩进),使这些存储库与上游同步并将我的最新代码推送到服务器(我的分叉分支),如下所示:

cd $d # traverse directory
&& git checkout master # checkout the master branch of my fork
&& git fetch -a # fetch all the branches
&& git fetch upstream # https://help.github.com/articles/syncing-a-fork/ 
&& git pull upstream master
&& git merge upstream/master
&& git commit -am "`date`" #commit the current code 
&& git push origin master #push the code to the master of my fork

我面临的挑战是使用上述脚本推送到我的origin / master不会成功。另一方面,如果我在命令提示符上按顺序执行所有命令,则可以正常工作。

我注意到提交和推送的组合让我很难执行脚本因为行为与在项目目录的命令行上单独执行以下操作相同:

git commit -am "`date`" && git push origin master  #results into no push

如果有可能的话:

git --version => 2.16.1

针对其中一个项目的上述脚本命令的按需样本日志:

Already on 'master'
Your branch is up to date with 'origin/master'.
remote: Counting objects: 350, done.
remote: Compressing objects: 100% (120/120), done.
...
From github.com:dropwizard/dropwizard
   4db822962..3f9cf2253  master     -> upstream/master
 * [new tag]             v1.3.0-rc5 -> v1.3.0-rc5
From github.com:dropwizard/dropwizard
 * branch                master     -> FETCH_HEAD
Updating 4db822962..3f9cf2253
Fast-forward
 docs/pom.xml                                                 |  2 +-
 .... # list of files wiht lines changed
++++++++++-----------
 49 files changed, 147 insertions(+), 116 deletions(-)
Already up to date.
On branch master
Your branch is ahead of 'origin/master' by 21 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

1 个答案:

答案 0 :(得分:0)

如果未提交任何内容,并且未执行git commit运算符之后的后续链,则

1返回&&(因为也需要成功0)。

在加入最后一个;时尝试使用&&而不是git push