Home > OS >  Running git reset --hard on my repo/branch does --NOT-- take me to the last commit. How to fix?
Running git reset --hard on my repo/branch does --NOT-- take me to the last commit. How to fix?

Time:09-22

as above. Might be best explain with screenshot/example.


Here's the latest commits for my test branch.

enter image description here

Here are the console commands.

  • If you refer to the first git log, the last commit on the branch is "42a90f86f992ca3e346597f9f639ef4cb7e3cf19" (which should correspond to the commit in the screenshot).
  • I then run git reset --hard, this should take me back to the same commit but for some reason, it's resetting to a much older commit.
$ git branch
* test

$ git pull origin test
From bitbucket.org:flinderswebtransformation/scholarships-system
 * branch            test       -> FETCH_HEAD
Already up-to-date.
$ git log
commit 42a90f86f992ca3e346597f9f639ef4cb7e3cf19
Merge: 6ace73c ef6af98
Author: my-user <[email protected]>
Date:   Tue Sep 21 06:37:35 2021  0000

    Merged in dev (pull request #22)
    
    changed datasources for dev and test

commit ef6af98d28aebd00e2d0a80c775d31c35d243fee
Author: my-user <[email protected]>
Date:   Tue Sep 21 16:06:46 2021  0930

    changed datasources for dev and test

$ git reset --hard origin/test
HEAD is now at 4b2c4a3 Merged in bug/SP-1790-remove-references-css-js-and-etc (pull request #17)

$ git log
commit 4b2c4a36467fd6711e8a7193471c67335b59e14d
Merge: a0fd07e 868b500
Author: my-user <[email protected]>
Date:   Mon Aug 5 01:00:55 2019  0000

    Merged in bug/SP-1790-remove-references-css-js-and-etc (pull request #17)
    
    fixed references to assets and updated links to use AEM ones
    
    Approved-by: my-user <[email protected]>

commit 868b5006adea72c1e69ec54266caf13c4870cb5e
Author: my-user <[email protected]>
Date:   Mon Aug 5 10:15:26 2019  0930

    fixed references to assets and updated links to use AEM ones

$

CodePudding user response:

git reset --hard HEAD~1 ( this will delete your last commit and file too )

CodePudding user response:

Try this

git reset --hard 'your SHA Commit id'

Example: git reset --hard 'ef6af98'

  •  Tags:  
  • git
  • Related