Git Workflow Issue: git push, git reset --soft HEAD~1 and how to push updated code to new branch?
Git Workflow Issue: git push, git reset --soft HEAD~1 and how to push updated code to new branch?
I am quite new to the git workflow. I made a mess and I need help to untangle it. This is what happened:
What I would like to do:
Any help is greatly appreciative.
revert
reflog
revert
push
Yes, that's what I ended up doing resetting my reset with git reset HEAD@1; and then git reflog to get the specific commit number and git revet <commit>. Thank you so much for help!
– lukrecija
Aug 31 at 19:07
1 Answer
1
When you did git reset, you only undid the commit locally. You need to make the same change in remote as well.
git reset
git reset --soft HEAD~1
git stash
--force-with-lease
WARNING: Be very careful when using --force-with-lease flag, you may lose changes. It's always a good idea to backup your code incase things go wrong.
--force-with-lease
Edit 1: This will work only if force pushes are allowed on the branch. If not, git revert is one option.
Edit 2: As pointed by philippe --force-with-lease is a better approach.
--force-with-lease
More info about --force-with-lease here.
--force-with-lease
--force-with-lease is most of the time much better than -f/--force and should be preferred to avoid loosing other developers commits– Philippe
Aug 29 at 12:27
--force-with-lease
-f
--force
Interesting, I did not know about
--force-with-lease.– Rajeev Desai
Aug 30 at 6:54
--force-with-lease
Thank you Phillipe for taking the time to provide a solution. I was not comfortable doing the force flag (as i am still new to this and project is huge involving teams), so i just reverted my commit.
– lukrecija
Aug 31 at 19:10
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You still could do a
revertif you thing it's the right thing to do. Look at the commandreflogto be able to reinstate how your history was. And then do yourrevertand (normal)push– Philippe
Aug 29 at 12:26