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
1 answer

Update(fetch + reset) a branch A from remote without a pull after a fetch?

On my repo I have a master and dev branches. When I make changes to the dev, and the master have new commits I do a git fetch to check first if there is some new commit on the master branch. If there is some new commit i can do a git pull origin…
pvsfair
  • 161
  • 1
  • 13
0
votes
1 answer

Recover data after command git reset --hard

I wrote some code after the last commit. After that, I accidentally did git reset --hard. My code rolled back to the last commit. Can I restore uncommitted changes?
Konstantin
  • 35
  • 1
  • 5
0
votes
1 answer

Clarification with how GitHub's pull request works and merging in general. What must be done?

Recently, we've been merging topic branches to our development branches. Here's the thing: right after a topic branch has been merged to development branch (thru a pull request), a new change needs to be introduced to that topic branch to fix some…
Valkyrurr
  • 119
  • 1
  • 12
0
votes
1 answer

Is it possible to move a Git branch right to the last rebase?

I just rebased a Git branch called chattisekoilua onto the master branch of my project, did something stupid on chattisekoilua (as in deleted some files I shouldn't have) and would like to set the state of the chattisekoilua branch to the moment…
sesodesa
  • 1,473
  • 2
  • 15
  • 24
0
votes
0 answers

How do I recover a file deleted from git using filter branch and pushed to remote?

I recently cleaned out several files from my repository using git filter branch. These are the instructions I followed : https://help.github.com/articles/removing-sensitive-data-from-a-repository/. After that I rebased my development branch so that…
NSM
  • 35
  • 2
  • 5
0
votes
0 answers

Why git reset files to previous versions?

You see, I have a problem with git in my computer. I typed clone command in my console, but three files are modified right there to previous versions. so... when I open the IDE, the three files has modified tags. I tried clone command many times…
esleidera
  • 1
  • 2
0
votes
1 answer

Different between git reset --soft and git reset

What is the difference between git reset --soft origin/dev and git reset origin/dev Hopefully it's not a big difference because I might have just screwed something up by accident.
user5047085
0
votes
1 answer

Using git reset - does it remove commits - looking to save disk space

If I have a bunch of merge commits on a branch, if I use git reset --soft will git remove/delete the commits between old_sha and the most current commit - git does garbage collection right? Just looking to save disk space.
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
1 answer

How is `git pull --rebase` different than `git reset --soft origin/b`

I am trying to understand git pull --rebase...in order to do so, how is that command different from: git fetch origin git reset --soft remotes/origin/foo git add . git commit -am "bar" git merge remotes/origin/foo is git pull --rebase the same as…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
1 answer

git reset --soft to save face with big files

So I accidentally pushed some big files to Github on master branch. After I did that, I tried doing: git reset --soft HEAD~2 then I removed the big files, committed, then tried pushing to the remote master, but I get an error saying my local branch…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
0 answers

Git Revert a commit back to staging area

State1: A file has a value 'A' State2: value changed to 'B' State3: Git add(put in index/staging area) State4: File committed(put in repository) I want to do a revert to get to State3(put in staging area) or just state2. Effectively deleting the…
Blue Clouds
  • 7,295
  • 4
  • 71
  • 112
0
votes
0 answers

GitHub: Reverted a bad merge to master, but merged files are still present

In GitHub, I accidentally merged the wrong branch into master. (probably from a slip of the finger when selecting from the dropdown) The merge was completed and pushed before I realized my error. I've looked at: Reverting a bad git merge from…
MarkTO
  • 247
  • 2
  • 11
0
votes
1 answer

Git: Is it possible to recover my local unstaged changes (which were once staged) after a git reset --hard?

I had some changes in my local branch which I added using git add -A. Then for some reasons I unstaged these changes by doing git reset. Then I opened GitExtensions and clicked on Reset all changes. (I somehow assumed that it was Reset selected…
Ajinkya
  • 1,231
  • 1
  • 9
  • 10
0
votes
2 answers

Git Pulling commits reset in different machine

I had Commit A, B, C in my repo (A is the latest) which I am working on my office computer and private computer. Then I reset commit A, B from my private computer and added new commit D. Now my private computer has commits D, C. Then I force pushed…
Chamila Wijayarathna
  • 1,815
  • 5
  • 30
  • 54
0
votes
2 answers

"amend" previous commit and edit the message

Let say that I want to change HEAD~2 by my current last commit "HEAD" without the change made by HEAD~. Moreover, I'd like to edit the message from HEAD~2 and not overwrite it (just few changes should be done on the message). I found that way : this…