devamat
devamat

Reputation: 2503

Some issue with version control

Today at work I tried to update my local files and I got this message:

...git pull origin master
From https://github.com/.../ez-class
 * branch            master     -> FETCH_HEAD
 + ace98f3...145956d master     -> origin/master  (forced update)
Already up to date.

Then this is what I did:

...>git fetch

...>git reset origin/master --hard
HEAD is now at 145956d hello

...>git pull
Already up to date.

...>git pull origin master
From https://github.com/.../ez-class
 * branch            master     -> FETCH_HEAD
Already up to date.

It looks like all my changes on the remote repository are gone as well as locally. I'm not sure what happened here... and is there any way I can fix this?

Upvotes: 0

Views: 138

Answers (2)

VonC
VonC

Reputation: 1323135

all my updates on the remote repository are gone

When you force push from home to office, you overrode the history of the master branch of office.

When you will have access your office, you can use git reflog to list the commit which was before your latest forced push. You can reset it to its old state.

Then, from home:

  • clone office repo again (in a new folder)
  • report your latest changes
  • add, commit, and push

More generally, for synchronizing files, Steve Gibson mentions several alternatives in:

Mainly:

Upvotes: 1

Blue
Blue

Reputation: 748

What might have happened is you edited history with something like a rebase, or you happened to be in a different branch that didn't have your updates. Git gives you that warning when the history of your branches isn't compatible, and --force overwrites that history instead of simply adding new commits. I like to use git push, and default to the branch with the same name, instead of git push origin master. That helps prevent something like pushing to master from the wrong, out of date branch.

The good thing about git is that it doesn't delete commits, it only creates new ones. Your computer with the correct updates still has them. You can find them with git reflog. That shows you the history of your HEAD commit, which changes as you do your work. You can find the commit that looks right and run git checkout <commit-id> to see if that's the state you want. Then you can either create a new branch at that commit (git checkout -b recovery-test), or just switch back to master and reset master to that commit (git checkout master; git reset <commit-id>).

Upvotes: 1

Related Questions