bash GIT 致命:模棱两可的参数“HEAD”:未知的修订版或路径不在 Travis 的工作树中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37303969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:38:45  来源:igfitidea点击:

GIT fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree in Travis

gitbashcontinuous-integrationtravis-ci

提问by vcernomschi

I have the following configuration: git version 1.8.5.6 GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)

我有以下配置: git version 1.8.5.6 GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)

I called zgit_info_updateand also tried to make commit. But I am still encountering with issue when run git diff --name-only devfrom bash in Travis (https://github.com/travis-ci/travis-ci/issues/6069).

我打电话zgit_info_update并尝试提交。但是git diff --name-only dev在 Travis ( https://github.com/travis-ci/travis-ci/issues/6069) 中从 bash运行时,我仍然遇到问题。

Can somebody assist to get this working?

有人可以协助完成这项工作吗?

Here the output:

这里的输出:

git version 1.8.5.6
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later       <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
* (detached from FETCH_HEAD)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
[detached HEAD 72afa70] Add package.json
 1 file changed, 37 insertions(+)
 create mode 100644 package.json
fatal: ambiguous argument 'dev': unknown revision or path not in the   working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

回答by vcernomschi

The issue was fixed by using commands below:

该问题已通过使用以下命令修复:

if [ "$TRAVIS" == "true" ]; then
  #resolving `detached HEAD` by attaching HEAD to the `TRAVIS_FROM_BRANCH` branch
  TRAVIS_FROM_BRANCH="travis_from_branch"
  git branch $TRAVIS_FROM_BRANCH
  git checkout $TRAVIS_FROM_BRANCH

  #fetching `TRAVIS_BRANCH` branch
  git fetch origin $TRAVIS_BRANCH
  git checkout -qf FETCH_HEAD
  git branch $TRAVIS_BRANCH
  git checkout $TRAVIS_BRANCH

  #switch to `TRAVIS_FROM_BRANCH`
  git checkout $TRAVIS_FROM_BRANCH
fi