简体   繁体   中英

How to revert all changes to the remote feature branch?

So I have a remote feature branch that was pulled from master a few days ago. Within that time there were files added. I made several commits to the PR of my feature branch feature/XYZ and then I wanted to squash the recent so I followed all the correct steps for squashing and then all of a sudden git won't let me commit to my remote branch. I got the following error:

error: failed to push some refs to 'ssh://git@............git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So I went online to find what was wrong and I tried everything from git fetch to git pull --rebase to setting the git branch upstream or something like that and nothing seemed to work. So I decided I don't need to squash the commits for now and just want to go back to before since I have some important stuff to work on and commit. My last resort is to save the files on my system and delete the feature branch and start from scratch and submit another PR but I don't want to do that if there is an alternative.

It was working fine when I was committing changes in lines of code. Is it possible to forget that I ever squashed the changes and go back to the same status and changes as the remote branch?

Check your remote tracking branch associated to your feature branch

git switch yourFeatureBranch
# or (older git)
git checkout yourFeatureBranch

git branch -avv

You should see:

* yourFeatureBranch  <sha> [origin/yourFeatureBranch]

If not:

git push --force -u origin yourFeatureBranch:yourFeatureBranch  

That should force update the remote origin/yourFeatureBranch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM