简体   繁体   English

无法使用git commit推送到分叉的仓库和使用脚本推送

[英]Unable to push to forked repo using git commit and push using a script

I have forked a repository on GitHub and clone the forked repository to my local with following .git/config : 我已经在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/*

Now that I have a script formulated(indented for question readability) for such repositories to be in sync with the upstream and pushing my latest code to the server (my forked branch) with something like this : 现在,我已经制定了一个脚本(旨在提高问题的可读性),以使此类存储库与上游同步,并使用以下内容将我的最新代码推送到服务器(我的分支分支):

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

The challenge that I am facing is that the push to my origin/master doesn't succeed with the above script. 我面临的挑战是上述脚本无法成功推送到我的原籍/母版。 On the other hand, if I execute all the commands sequentially on the command prompt it works. 另一方面,如果我在命令提示符下依次执行所有命令,则它会起作用。


What I noticed was that the combination of commit and push is making it difficult for me to execute the script since the behavior is same as when executing the following separately on the command line from project directory : 我注意到的是, commit和push组合使很难执行脚本,因为其行为与在项目目录的命令行中分别执行以下命令时相同:

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

If in case it may matter: 如果可能的话,请执行以下操作:

git --version => 2.16.1

On-demand sample logs against the above script commands for one of the projects : 针对上述项目之一的上述脚本命令的按需样本日志:

 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 

git commit returns 1 if nothing was committed and subsequent chain after && operator is not executed (because it requires success aka 0 ). 如果未git commit任何内容,并且未执行&&运算符后的后续链,则git commit返回1 (因为它需要成功,也就是0 )。

Try ; 尝试; instead of && when joining last git push 加入最后一个git push而不是&&

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

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