Questions tagged [git-reset]

Sets the current Git repo head to a specified commit and optionally resets the index and working tree to match.

If you've made a mistake in the current working tree, and haven't committed, you can revert the entire working tree to the last commit state with the following:

$ git reset --hard HEAD

Synopsis

git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
git reset [-q] [<commit>] [--] <paths>...
git reset --patch [<commit>] [--] [<paths>...]

Options

--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

--soft
Does not touch the index file nor the working tree at all, but requires them to be in a good order. This leaves all your changed files "Changes to be committed", as git status would put it.

--hard
Matches the working tree and index to that of the tree being switched to. Any changes to tracked files in the working tree since <commit> are lost.

--merge
Resets the index to match the tree recorded by the named commit, and updates the files that are different between the named commit and the current commit in the working tree.

--keep
Reset the index to the given commit, keeping local changes in the working tree since the current commit, while updating working tree files without local changes to what appears in the given commit. If a file that is different between the current commit and the given commit has local changes, reset is aborted.

-p, --patch
Interactively select hunks in the difference between the index and <commit> (defaults to HEAD). The chosen hunks are applied in reverse to the index. This means that git reset -p is the opposite of git add -p (see ).

-q, --quiet
Be quiet, only report errors.

<commit>
Commit to make the current HEAD. If not given defaults to HEAD.

See also

Reference

$ git reset --help
509 questions
-1
votes
1 answer

git reset --hard HEAD^ removed data from local drive

I copied a project and edited it to create a new project. I made a lot of changes. After 3 months, I tried to push to the repository. Pushed to the older repository. (All code was fine and complete.) git reset --hard HEAD^ git push origin -f these…
-1
votes
2 answers

Git reset --hard without dirty

I’m trying to solve a problem where I replace my current HEAD with a specific commit by doing git reset --hard (commit), but it always ends up dirty, which I would like to remove. I need help with some way to pull a commit and replace the current…
-1
votes
1 answer

How to undo very screwed Git merge and restore branch (accidentally turrned main into another branch and deleted the original)

The Problem OK, so, I had two branches: main and session In the main branch I developed the main code, in the session branch I developed code for a new session system. Occasionally, I merged main into session to keep it up to date. ("Merge branch…
-1
votes
1 answer

How do I undo a "git reset --hard ~HEAD" followed by "git reset ORIG_HEAD"?

Originally, I wanted to squash my last 6 commits into one. So I followed this answer and ran the following: git reset --hard HEAD~3 git reset --hard HEAD~2 git reset --hard HEAD~1 Then I saw that my code progress was gone and I was afraid that I…
Amrovic
  • 344
  • 5
  • 13
-1
votes
1 answer

git -- remove latest commit ... without messing up the working directory

The typical question is how to remove the latest commit. This is easy: git reset --hard HEAD~1 But ... I don't want the working directory to be overwritten with the new head contents. If you reset the head, the working directory is restored to the…
-1
votes
1 answer

Get untruncated list of files that would be overwritten by checkout

Suppose I want to check out branch X, and git says that many, many, many, VERY MANY files would be overwritten by checkout. So many in fact, that the list it writes out is truncated because it doesn't fit in some buffer. Is there a way to get the…
Szczepan Hołyszewski
  • 2,707
  • 2
  • 25
  • 39
-1
votes
1 answer

When doing git reset --soft HEAD~60 to sqaush commits is removes merges that have been done, how to avoid?

I followed the post on how to do squash commits from here so I did : git reset --soft HEAD~20 git commit git push -f I have a lot of commits and between them, I have few merges I did from the develop branch to my feature branch to update my branch…
user63898
  • 29,839
  • 85
  • 272
  • 514
-1
votes
4 answers

Revert Local GitHub Repo All The Way Back

I know you can go in order of reverting commits but is there a way to completely revert a repo to when it was first initialized? This sounds extreme but I messed up with my commits because I was trying to use an existing React project to replace an…
LaLaLottie
  • 393
  • 1
  • 4
  • 17
-1
votes
2 answers

What's the point of "edit" option in `git reset --patch"

What is the use case of git reset -p and then using "e" option to edit an applied hunk before resetting it ? I tried playing around with the command but all edits I tried were refused by git.
Moha the almighty camel
  • 4,327
  • 4
  • 30
  • 53
-1
votes
1 answer

Undo a git reset file command

I just ran this command: git reset origin/dev -- package-lock.json but I want to do undo it, I want to go back to: git reset HEAD -- package-lock.json but I think it might be too late to go back to HEAD...how do I undo the original command?…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
-1
votes
1 answer

Git removed all files

I just initialized a repository by applying git flow init git remote add origin git@gitlab.com:folder/project.git git add . I noticed that I needed to comment on a folder, then used git reset --hard And tried to add the folder to .gitignore, but…
dcandamil
  • 111
  • 2
  • 12
-1
votes
2 answers

Why are my local changes not being removed by git reset?

I have a git repository that for some reason is showing local changes I cannot revert. From a freshly cloned repo I see one configuration file changes with the following diff from git diff C:\Projects\NewUI>git diff diff --git…
Alexander Burke
  • 534
  • 7
  • 22
-1
votes
1 answer

How can I commit reversal of last commit?

I've just created a huge commit. Now I want to commit the reversal of these changes. So basically I want to have the same files in my repo as I'll have after git reset --hard HEAD~1, but I'd like to keep the history of my changes, so create a new…
Daniel Stradowski
  • 3,466
  • 1
  • 12
  • 21
-1
votes
2 answers

Is there any way to undo a "`git reset .`"? It 'reverted' all files - all edits have been lost from my working directory

I staged a grand number of files for commit. Then I realized it was better to commit only two of the files, and then commit the remaining ones in a separate commit. git reset unstages filename I wanted to unstage everything, then restage…
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
-1
votes
1 answer

Issues resetting git head

After working on my project and making a few commits, I decided to push and be done for a bit. However, an error occurred somewhere during the process and the project ended up getting severely messed up, with the majority of my changes being…
treyhakanson
  • 4,611
  • 2
  • 16
  • 33
1 2 3
33
34