0

While building my code in travis, in the case of failure I want reset HEAD to the previous commit and perform some action. The problem is when in travis.yml I do:

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

It always points to the latest commit.

If i do git reset --hard HEAD 04d24f1 I am getting fatal: Cannot do hard reset with paths. and printing hashes for some reason shows letter m next to the commit that i tried to reset to

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

If i print history of commits by git reflog -4, then I get only 2 commits and they both have the same hash

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

If i print history of commits by git log --oneline --graph --decorate, then it displays the history like this:

* 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

Additional info - At the beginning this is what travis doing before running commands:

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

Do you know why i'm not able to get reset while building on Travis?

Maxim Vershinin
  • 531
  • 1
  • 6
  • 12
  • What about `git reset --hard HEAD~1`? – Sajib Khan Jan 18 '19 at 17:39
  • 1
    @SajibKhan thanks a lot for suggestion. It did work, your answer is correct. I was thinking `git reset --hard HEAD@{1}` will do the same thing. Need to research what is difference between them. – Maxim Vershinin Jan 18 '19 at 18:11
  • The problem with `git reset --hard HEAD 04d24f1` is that there are two commits listed: `HEAD` is one, `04d24f1` is the other. You want either the sha1, like `04d24f1`, or something based on `HEAD`, but not both. So `git reset --hard 04d24f1` should have also worked. – joanis Jan 18 '19 at 18:57
  • https://stackoverflow.com/questions/26785118/head-vs-head-vs-head-also-known-as-tilde-vs-caret-vs-at-sign – phd Jan 18 '19 at 18:59

1 Answers1

0

As already pointed out by Sajib Khan, you want

git reset --hard HEAD~1

and not git reset --hard HEAD@{1}.


There is some useful information here, that explains the difference. *In short, HEAD, in your case never pointed anywhere other than (HEAD, origin/feature/RXM-73-create-aws-rollback-script, feature/RXM-73-create-aws-rollback-script), and @ notation is for where head was *.

You can investiagte the list of possible @{#} values by looking at

git reflog

in order to verify that HEAD did not point elsewhere.

9301293
  • 514
  • 3
  • 16