I mistakenly added files to master
and committed too. Otherwise I had to do it in a branch feature_x
Now I know there are commands like git reset
. My issue is, if I reset things, will it undo my code too or just undo files and commit in master
?
How do I avoid resetting things without losing code?
Update
Code has not been pushed on remote yet. When I tried it gave error:
error: src refspec feature_x does not match any.
You are currently on the master branch with the accidental commits X, Y and Z like this:
A - B - C - X - Y - Z <- master
Now you can create a new branch where you currently are using
git branch feature-x
The feature-x branch will point to the same commit as the master branch, making it safe to reset the master branch to the earlier version:
git reset --hard HEAD~3 # Move master branch 3 commits back
You now have this
X - Y - Z <- feature-x
/
A - B - C <- master
Now you can checkout the feature-x branch again:
git checkout feature-x
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