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
0
votes
3 answers

Undo changes made by 'git reset --hard '

Query is regarding git reset, Stage 1: Now I would like to revert back to a specific commit using the below command provided no local changes are there. git reset --hard Query 1: How I could make the revert to a new…
Rajesh Omanakuttan
  • 6,788
  • 7
  • 47
  • 85
0
votes
0 answers

Identifying user who ran “git reset” command

I came across a problem recently. One of the developers committed some changes in a branch. When he checked the branch log (git checkout branch; git log), the commit (say, abc) was showing up but when he checked the log for a file (git log…
Technext
  • 7,887
  • 9
  • 48
  • 76
0
votes
1 answer

Git keeps resetting my files after a hard reset?

I tried this solution with no lucK: How I can store some local changes that survives git reset --hard Basically I have a script on the server that deploys my git to sites. Even though I did: git update-index --no-skip-worktree --…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
0
votes
1 answer

GIT Reset --hard forces me to push a lot of files

I wanted to try out resetting to a specific commit locally. After doing a "git pull", I've done a "git reflog" to get the hash of the commit prior to doing the pull. Then, i tried doing a "git reset --hard hashTagIgotFromReflog". I recieved a…
0
votes
1 answer

Git head via post-update

I have a local dev server where I do all my changes, we'll call this local. I have a git repo setup in a git folder on my webserver, we'll call this gitfolder. And then I have my live files, that are being pushed from gitfolder everytime I git push,…
Brandon Shutter
  • 143
  • 2
  • 15
0
votes
1 answer

Pushing from Xcode caused faulty commits - GIT

I wanted to commit B to the remote master branch whose head is at A. I had previously committed code saved locally (say X). When I pushed B to the master this caused the following: A-----B / X--/ I just want B to committed. B should be on top…
Siddharthan Asokan
  • 4,321
  • 11
  • 44
  • 80
0
votes
1 answer

How to return a repository back to the state it was in three commits ago?

Consider this Git repository: $ git log -4 commit d7a65d3243259300ff133a28e952fd967df8ff24 Merge: 5572899 65d0d65 Date: Sun Jul 20 08:23:09 2014 -0400 Merge branch 'master' of ssh://foo/bar commit…
dotancohen
  • 30,064
  • 36
  • 138
  • 197
0
votes
2 answers

Why can I git show a commit I just did a git reset?

I did a git commit but I included files I should not have. Let's say commit 321232323232 That was the top commit. I did git reset --soft HEAD~1 and I can see my files as they were before I did the wrong commit and when I do a git log I don't see…
Jim
  • 18,826
  • 34
  • 135
  • 254
0
votes
1 answer

Git: reset deleted file from index

Create 2 files: one.txt and two.txt. Commit both files: git add -A and git commit -m "message" Edit one.txt and add it to index: git add one.txt Delete two.txt and add it to index: git rm two.txt I want to commit only one.txt, therefore I need to…
Aleks Ya
  • 859
  • 5
  • 15
  • 27
0
votes
3 answers

"git reset xxx" command on windows does not perform the same action as linux?

At the HEAD version, I have a mistake that pull another branch when I on master branch so that some new files or directories had been merged into master branch from another. I realize this is a very big mistake. So I use "git reset xxx" to restore…
Qinghua
  • 351
  • 3
  • 10
0
votes
1 answer

post_receive hook in git: how does it checkouts my non-git folder?

I am using webfaction for my web deployment. I have a Django app at: webapps/django_app/project_name/ I have a Git repo at: webapps/git_app/repos/my_repo.git my_repo.git is a bare repository. It is not a working directory. whenever I push from my…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
0
votes
1 answer

Is "git clean" followed by "git stash clear" redundant when creating a pristine checkout?

I would like to write a script that guarantees a successful Git checkout without intervention from the user. I don't mind dumping anything that cannot be solved without user intervention: for example, uncommitted changes. I do want to keep…
lofidevops
  • 15,528
  • 14
  • 79
  • 119
0
votes
1 answer

Trouble pushing to origin after local hard reset

I recently did a hard reset of my local git repository: In other words I reset it to an earlier point in time. Now when I try to push up to the origin it tells me that it can't because the origin contains work of a later date than my repository.…
sectornitad
  • 973
  • 3
  • 11
  • 20
0
votes
2 answers

having trouble reversing commit - commits from origin to pull not wanted

In source tree, I am 4 behind after resetting to an earlier commit, so the other commits from origin are still present. How can I 'tell' origin that I don't want them?
0
votes
1 answer

eclipse git revert/reset option not found

How can revert/reset a file using the eclipse egit (team) plugin? I'm opening the team menu but can't find any reset/revert option. See screenshot:
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277