5
math-silva
318d

Sometimes your day is going really nice, and you just had a nice cup of tea with the milk from the best cow on the farm. You're coding happy, and you will take a walk after that. Then, suddenly, you type `git checkout .` rather than `git reset HEAD .` and your life is miserable now.

Comments
  • 2
    Thank god my IDE has a local history for that
  • 2
    Yes, it is horrible and terrible. The Git book explains it in detail -
    https://git-scm.com/book/en/...

    Though it looks too long to read, I believe the first half of article should be present in the basics section before teaching what git commands mean and do

    But I learnt my lesson long ago to not keep huge chunks of changes in the working directory. Frequent commits (and pushes, of course) and small commits make the developer life a lot more manageable and disaster-recoveryable
  • 2
    @AtuM @math-silva git reflog , literally a lifesaver
  • 0
    Can someone translate to non git terms?

    Dunno what the diff is btwn reset n checkout...

    I use GitExtensions... Just commit, pull, push, checkout and usually always at the HEAD of whatever branch im in.
  • 1
    @donuts in Git you have working and staging area. When you want to push something to the repository, you put the changes in the staging area before committing and pushing it to the repository. You use `reset` to remove something from the staging area, so, you don't want to commit this yet. You use checkout when you don't want the changes, so, it gets back to the version committed. Also, I'm not trying to be extensive here, but it's basically it.
  • 0
    @asgs finally read that page. Good recommendation except it didn't seem to work like that when I tried reset last week.

    Somehow after a commit the whole local branch messed up... Said a whole bunch of files were now changed... But didn't.

    Remote was fine though...

    I tried reset --hard but it didn't do anything.
    Then tried reverting all the "changes" and then manually downloaded and extracted the remote files over the working dir...

    Which somehow added all the changes back.

    Finally, Reverted again then switched to the main branch, did a pull then deleted the other branch and checked it out from remote.

    This worked but isn't this was reset --hard was supposed to do and well how come overwriting didn't work either?
  • 0
    Only thing I can think of is the the Working dir tree got moved to like v1 somehow?

    How do you check and move it back to the latest? Without basically doing a format and reinstall?
  • 0
    @donuts if you don't specify a commit, then it doesn't change the working directory
  • 0
    @asgs but I can't understand after I commit and push, how did the local get out of sync.

    Read online at the time something about a local cache but didn't really get it. And I think it said reset --hard would fix it.. Except it didn't.
  • 0
    @donuts if you can share the exact history of commands, we could understand the situation better. Paraphrasing doesn't really help
Add Comment