Vidya
Vidya

Reputation: 31

TortoiseGit - How to perform a git reset --hard <by reading the commit hash from a file>

How to perform a git reset --hard - by reading the commit hash from a file

Upvotes: 1

Views: 2626

Answers (2)

Gino Mempin
Gino Mempin

Reputation: 29598

I'm assuming you're on Windows because of the TortoiseGit in the title.

Given a hash.txt with just "a7abda785" as its contents (or any hash for that matter), you can run this batch file to do git reset using the hash from hash.txt:

@echo off

set /p HASH= < hash.txt
git reset --hard %HASH%

The /p sets the variable by prompting the user for input, which we automatically provide by redirecting the contents of the file.

With this script, you can include:

  1. Putting a different hash into hash.txt
    (I assume you are using some other command or script to write the hash to the text file)
  2. Skipping git reset if the hash is invalid (i.e. empty)

Upvotes: 1

Yue Lin Ho
Yue Lin Ho

Reputation: 3111

  1. Open Reset dialog

    • Open Log Message dialog
    • Right click on any commit
    • Click Reset "xxx" to this...
      enter image description here
  2. Reset Hard [sha-1]

    • Copy the sha-1 value from your file
    • Paste it into Commit text filed
    • Click the Hard option
    • Push OK button
      enter image description here
  3. Refresh the Log dialog


BTW, if the file is .git/FETCH_HEAD, you can just view that commit by this way:

enter image description here

Upvotes: 2

Related Questions