Hacker News new | ask | show | jobs
by swah 4868 days ago
I thought I knew enough git, but the other day I was still able to lose my changes...

Suppose I'm in master and already modified a file, and now I notice that it would be better to work on a devel branch with those changes, so I could pull upstream changes from master and merge locally. I think I did something like this:

  git stash
  git checkout -b devel
  git stash apply
  git add file.txt
  git commit -m "XYZ new changes" 

  git checkout master
  git fetch
  git rebase origin/master (to avoid an empty merge, changes
                            upstream were in independent files)
  git merge devel (to get commit "XYZ")
In the end of this, I had lost my changes in file.txt.