0

在 travis 中构建我的代码时,如果失败,我希望将 HEAD 重置为上一个提交并执行一些操作。问题是当travis.yml我这样做时:

after_failure:
- git reset --hard HEAD@{1}

它总是指向最新的提交。

如果我这样做了,git reset --hard HEAD 04d24f1我会fatal: Cannot do hard reset with paths.出于某种原因获取并打印哈希值,m在我尝试重置为的提交旁边显示字母

1b8bc73 (HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script) Fail 7
* 04d24f1m Pass 7  << letter m added
* 8c6a51e Fail 6
* 37e3e38 Pass 6

如果我打印提交的历史记录git reflog -4,那么我只会得到 2 个提交,并且它们都具有相同的哈希值

1b8bc73 (HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script) HEAD@{0}: checkout: moving from feature/RXM-73-create-aws-rollback-script to 1b8bc736d2297be68e18d13de74dde3f75694072
1b8bc73 (HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script) HEAD@{1}: clone: from https://github.com/MaxRepo/terraform-rx-manager-service.git

如果我打印提交的历史记录git log --oneline --graph --decorate,那么它会显示这样的历史记录:

* 1b8bc73 (HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script) Fail 7
* 04d24f1m Pass 7
* 8c6a51e Fail 6
* 37e3e38 Pass 6
* 4ddfd89 Pass 5

附加信息 - 一开始这是 travis 在运行命令之前所做的事情:

0.74s$ git clone --depth=50 --branch=feature/RXM-73-create-aws-rollback-script https://github.com/MaxRepo/terraform-rx-manager-service.git MaxRepo/terraform-rx-manager-service
Cloning into 'MaxRepo/terraform-rx-manager-service'...
remote: Enumerating objects: 118, done.
remote: Counting objects: 100% (118/118), done.
remote: Compressing objects: 100% (91/91), done.
remote: Total 175 (delta 52), reused 61 (delta 22), pack-reused 57
Receiving objects: 100% (175/175), 32.98 KiB | 8.24 MiB/s, done.
Resolving deltas: 100% (66/66), done.
$ cd MaxRepo/terraform-rx-manager-service
$ git checkout -qf 1b8bc736d2297be68e18d13de74dde3f75694072

你知道为什么我不能get reset在 Travis 上构建吗?

4

1 回答 1

0

正如 Sajib Khan 已经指出的那样,你想要

git reset --hard HEAD~1

而不是git reset --hard HEAD@{1}


这里有一些有用的信息,可以解释差异。*简而言之,HEAD在您的情况下,从未指向除 之外的任何地方(HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script),并且@符号表示 head 所在的位置*

您可以通过查看来调查可能@{#}值的列表

git reflog

为了验证HEAD没有指向其他地方。

于 2019-01-18T19:05:46.460 回答