0

This is the state of the local branch before I did anything:

B<-A...

And this is the remote:

B<-A...

I was running git add -A on the repository and observed that it's taking too long. Turned out I hadn't ignored directory v3 with large development artifacts. So I ran git reset HEAD^ to get the index to look like what it did before running add and then added the v3 directory to .gitignore, ran add again and committed the changes (call this commit C).

Git started complaining when I tried to push things to remote. Turned out by running reset HEAD^ without having committed anything yet, I had jumped too far back in history and the local branched looked as below:

C<-A...

This creates a conflict where remote has B and local doesn't. The correct command I had to run was git reset HEAD. How do I fix this?

Paghillect
  • 822
  • 1
  • 11
  • 30

2 Answers2

1

So I ran git reset HEAD^ to get the index to look like what it did before running add

That should have been git reset (short for git reset HEAD)

Try git reflog to see what HEAD was before your git reset, and git reset to that commit.
Save first your work, just in case those commands don't behave as expected.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You just need to rebase your changes onto the remote branch.

Assuming you're working on master, with remote origin/master, just do:

git rebase origin/master

and that will move C after B instead of after A.

joanis
  • 10,635
  • 14
  • 30
  • 40