One late night, in paranoid fear of loosing my progress to hardware failure or something out of the ether, I decided to push master to origin. So I decided to work locally by amending my last commit every time I wanted to save my progress on the main branch (I know, I should've branched out, committed on that, kept pushing and later merge back to master). Since I had a similar situation, I thought I'd share my situation and how these answers helped me (thanks everyone). How can I fix this issue? The things that I'm looking for is Head of local/master and origin/master point to same commit. Since, I reset the head of origin/master I expect local and origin should be in same direction but as you see, git is saying that my local/master is behind origin/master by 7 commits. (use "git pull" to update your local branch) Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded. $ git commit -m "Reverting to the state of the project at e3f1e37"įinally, I checkout to my local master. Then I tried to add commit to origin/header that I was not successful. HEAD is now at e3f1e37 development version code incremented for new build. its okay now.Īnd reset the header by this command: $ git reset -hard e3f1e37 If you want to create a new branch to retain commits you create, you mayĭo so (now or later) by using -b with the checkout command again. State without impacting any branches by performing another checkout. You can look around, make experimentalĬhanges and commit them, and you can discard any commits you make in this Since I want to reset origin/header as well, I checkout to origin/master: $ git checkout origin/master Nothing to commit, working directory clean # (use "git pull" to update your local branch) # Your branch is behind 'origin/master' by 7 commits, and can be fast-forwarded. When I enter $ git status command, terminal says: # On branch master I encountered mis-deletetion when combined with DDEV.I reset my local master to a commit by this command: git reset -hard e3f1e37 It is worth noting there is also an interative mode ( -interactive) which will ask you about specific files and/or folders. git cleanīe aware though, with the (in)correct flags it may remove config files & folders too. gitignored) you can run the following command. If you want to get rid of everything that is not committed (and not. Remove everything in your repository that shouldn't be there If running this independently then ensure a git fetch is run first. This last one only works correctly as a git fetch origin was run beforehand. Reset your current main branch back to what is on origin git reset -hard origin/main Remove all existing stashes git stash clear git branch | grep -invert-match "main" | xargs git branch -deleteĬlean any remote branches your repository thinks it knows about that no longer exist git fetch origin -prune Replace main with your primary branch name below. ![]() We ran through the following commands which got the local repository nice and clean and back to it's original state. We didn't want to delete the folder again as we use ddev for our local development and doing that would clear out config files - something which can be rebuilt but would be easier if we could avoid it. I recently had to help a colleague get their local Git repo back to what was on the origin (Github/Gitlab etc.). Stale branches, people forgetting to push to origin and mixed commits with rebases and cherry-picks are all ingredients for a big fresh pot of what-the-hell with a side of rm -rf. With a myriad of branches and developers, Git repositories can quickly get in a muddle.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |