local changes lost when github push is rejected by remote

Answered

I was trying to push my changes to a private Github repository but was rejected by the remote repository. This repository is protected against pushes and I now realise I had picked the wrong branch.

How do I recover the local changes so I can push them to the correct branch?

1
11 comments

Also, is this a bug? Shouldn't I get a warning preventing me from pushing in this case and leave my local changes untouched?

0

Under local changes, you mean uncommitted files, right?

Check the git stash (VCS - Git - Unstash), most likely they are in there.

I think this could happen if you have the Auto-update if push of the current branch was rejected option enabled in Settings - Version control - Git. 

 

0

Yes, I meant my uncommitted files.

The Auto-update setting is off.

I did find my files in the stash, but only after I created a new project and re-cloned the repo and fixed up the missing files.

0

If the Auto-update setting is off, on a push reject a dialog should be shown asking what you would like to do (e.g. update with rebase or with merge, cancel, etc). If you select e.g update with rebase, all uncommitted changes are stashed. After rebase is finished, the changes are automatically unstashed.

If rebase fails for some reason, changes are not automatically unstashedat the moment, unfortunately - https://youtrack.jetbrains.com/issue/IDEA-160604

0

It just happened again, I pushed my changes to the branch on GitHub and it was rejected by GitHub due to conflicts that need resolving which I then resolved and at the completion of the resolution, I get:-

Push rejected
Push has been cancelled, because there were conflicts during update.
Check that conflicts were resolved correctly, and invoke push again.
View files updated during the push

and the modified files are no longer in the list of local changes and they're not in the stash, but they do differ from what's in the repository. I tried resync files, but nothing happened.

0

I also moved a file from one directory to another using IntelliJ's drag and drop in the project tab, but it didn't get moved when I pushed it.

0

The notification says

View files updated during the push

This means the Auto-update on reject is enabled.

So the scenario is:

1. You Push, and it is rejected

2. IDEA automatically updates

3. Conflicts occur during the update that need manual resolution.

4. Push get canceled because conflicts need to be resolved manually, then committed, and then you can push 

Not sure why the files are not in the stash, maybe they got stashed and resulted in some other conflicts as well. Need more details to tell - e.g. list of local changes, the updated files list, logs.

You could submit a request at https://youtrack.jetbrains.com/issues/IDEA (privately, if you want) and attach the mentioned details.

> I also moved a file from one directory to another using IntelliJ's drag and drop in the project tab, but it didn't get moved when I pushed it.

Most likely the commit that contains the move was not pushed due to the above scenario.

 

0

I think the problem is the Commit and Push command is not atomic. If the Push fails or is canceled, the Commit is not reversed.

0

 

And why should it be atomic? Reverting a commit on a failed push is totally unexpected. Git is a DVCS, thus push is optional operation. If it fails for some reason, you could retry it later, if e.g. server is unreachable, or resolve conflicts and push.

0
Avatar
Permanently deleted user

To Perform Failed push again Go to VCS->Git->push . you can see all your changes and you can push it again to remotre

0
Avatar
Permanently deleted user
  • Git checkout to the right branch or a new branch.
  • Go to VCS -> Git -> Push
  • Now you can see all the changes you were trying to push

 

1

Please sign in to leave a comment.