I modified some files in my branch and did a
git add --all
But this added some files that I didn't intend to add for the commit.
So I did a
git reset --soft HEAD~2 (instead of doing git reset HEAD)
But the previous commit was made by someone else and it caused a lot of files to be in modified/added/deleted status. Is there a way to get back to a stage where the only changes I see are the files added/modified by me? Since I didnt make an actual commit, is there a way to move my head back to master without blowing away my changes? git pull is causing merge conflicts as I didn't actually commit my changes.
Thanks!
Git Reset 1 Reset a file or set of files. The following command lets you selectively choose chunks of content and revert or unstage it. 2 Unstage a file. The changes you made will still be in the file, this command just removes that file from your staging area. 3 Reset a branch to a prior commit. ... 4 Important Note About Hard Resets. ...
We have executed a 'soft reset'. Examining the repo state with git status and git ls-files shows that nothing has changed. This is expected behavior. A soft reset will only reset the Commit History. By default, git reset is invoked with HEAD as the target commit.
lastly, git reset --hard wipes everything out including your local changes. The ~ after head tells you how many commits to go to from the top. You can use git reset --soft to change the version you want to have as parent for the changes you have in your index and working tree.
Suppose that you have run git reset HEAD~1 by mistake, which has deleted the latest commit from your local branch and, now, you want to restore that commit. Below, we will demonstrate how to do it. Git keeps a log of all reference updates (e.g., checkout, reset, commit, merge). Run the git reflog command to view them:
For future reference, you can review the commits that your behavior causes or leaves behind by calling git reflog
, which will include commits that are no longer in your working tree.
Just do git reset master
. This will only update the index and what HEAD
points to. It will not modify your work tree files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With