0

I'm in this scenario pretty often and I don't know what to do.

  1. I was changed something in a branch. Commited & pushed.
  2. I was still working on same branch and somebody commited & pushed.
  3. I was done changing and did git commit -m "Blabla" and pushed.
  4. Git refused to push because repository is ahead and I may loose some changes

My idea is to:

  • Go pre git commit -m "blabla" (<- this is where I'm stuck)
  • stash changes
  • Pull latest changes from repo
  • Merge stash with working directory
  • Commit once more
  • Push

How do you resolve such "conflicts", or what is the best thing to do in this situation?

ewooycom
  • 2,651
  • 5
  • 30
  • 52

2 Answers2

3

There is no need to drop/stash your commit. To resolve the conflict, use git pull --rebase and your commit from step 3 will be automatically rebased (stacked upon) the coworker's commits from step 2. After the rebase you will be able to push without the conflict.

user4815162342
  • 141,790
  • 18
  • 296
  • 355
0

The previous answer provides a better means of reaching your ultimate goal, but the answer for the question you asked is:

git reset HEAD~

That will rewind your current branch to point to the commit before the most recent one, but leave the index and working tree unchanged from their current states.

Community
  • 1
  • 1
qqx
  • 18,947
  • 4
  • 64
  • 68