Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a git hard reset remove stash?

Tags:

git

Just wanted to understand if the git reset --hard origin/master command affect my stash stack. I am yet to try this out but I do not want it to reset my stash as I have some changes I want to apply after my branch is reset.

like image 607
richik jaiswal Avatar asked Jan 25 '21 07:01

richik jaiswal


People also ask

What does git hard reset do?

To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory. There are three command line options that correspond to the three trees.

What is the difference between git reset and git stash?

Git stash vs.A reset creates a new commit point in the branch history; stash does not. A reset can jump back to any prior commit; a stash can only reset the files in the workspace to the point of the previous commit. A hard reset will discard all changes; a stash saves a snapshot of all locally modified files.

Does git reset hard remove history?

They all rewrite Git history, and they all move the HEAD back, but they deal with the changes differently: git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory.

How do you reset stash?

You can reapply the stashed content by running git stash apply . You can also apply a specific stash (if you have stashed more than once) by running git stash apply stash@{1} (the '1' denotes the second before the last stash).


Video Answer


2 Answers

No, git reset --hard origin/master does not affect your stashes in any way.

like image 164
1615903 Avatar answered Oct 23 '22 22:10

1615903


The hard reset command you showed above would move the HEAD pointer of whatever the current branch might be to origin/master, but it would not affect the stash commits, which are stored in .git/refs/stash.

like image 21
Tim Biegeleisen Avatar answered Oct 23 '22 22:10

Tim Biegeleisen