0

Me and my partners are working on the git remote and both have write access to the remote.

He did some changes, commited them and pushed them to remote,

I did few changes in my machine and without fetching/pulling just force pushed my commits. Which in turn resulted in lost of the commits of my partner.

So I have 2 questions:

1. Is there any way to get those commits back?

2. After my push, will my partners fetch, pull remove the changes he did, from his machine as well?

michaeltwofish
  • 4,096
  • 3
  • 28
  • 32

1 Answers1

0

If you push commits that overwrite someone else's code, and didn't pull; git will throw an error something like this:

error: failed to push some refs to 'git@github.com:foo'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.

On the off chance that you actually did overwrite something, you can revert your entire git repo. See this stack overflow question for an example: How do I restore files to previous states in git?

Community
  • 1
  • 1
spuder
  • 17,437
  • 19
  • 87
  • 153