I accidentally saved a file on the wrong branch. Then I did git reset --soft HEAD^ and now git status says I’m behind by 14 commits and lists a bunch of modified files in red. Including some untracked files.
I have no idea what to do. I tried to go to the latest commit from the remote repo but it says my local changes would be overwritten after I do git pull.
Help. I don’t wanna mess up my local repo even more. I just want to get back to the state I was in, save the edited file in the correct branch, and commit.
If you have changed your local branch, and do not want to lose any change, you can use git-stash. Before any attempt, I recommend you to backup your local repository. Try the following steps:
git stash save 'local changes'.This will save your local changes in a temporary place, and let you work on the current branch without any of these previous changes.
git pull <remote-name> <branch-name>. As you already know, it will retrieve newer commits from the remote branch, and apply to your local branch.git stash pop. This will revert what you did in step 1. It will apply your previous changes (those you saved) against the local branch. You are responsible for resolving any conflicts, if any occur. Once done, you may want to commit, and push – it’s up to you.