2

Me and my co-worker working on same repository, and my co-worker did mistake, he edited my files and just pushed.

The problem is that I'm also currently working at same file, so if I pull the commit, it will remove every my works.

Files are binary so I can't edit from the text editor. This is what exactly explain of current situations:

Commit 1. I made some binary files, for example: a.bin, b.bin, c.bin and pushed to master branch as commit [1]

Commit 2. My co-worker pull commit [1] and pushed what he worked as [2]

Commit 3. My co-worker accidentally edited my binary files: a.bin, b.bin, c.bin but he just pushed as commit [3]

Commit 4+: My co-worker just keep pushed..

So what I want is just rollback the commits, back to the old specific commit. I searched about git rebase and git revert, but it seems quite not working to me.

I heard that using merge also work, but I want to my history keep clean!

All I want is get everything back to the old commit, but it keeps saying that you have somekind of unmerged or unstaged files over there and keep fails with it. I just want to override to old files.

How do I solve this?

modernator
  • 4,341
  • 12
  • 47
  • 76
  • What is the exact git commit tree, inside git with the default workflow, git commits have multiple parents – Ferrybig Sep 20 '17 at 06:31
  • Is extracting the binaries from commit [1] and commit them on top of the latest commit an option? – Fabien Bouleau Sep 20 '17 at 06:37
  • Are you trying to rollback the binary files to the old commit or the entire project (losing your co-worker's commits)? – Fabien Bouleau Sep 20 '17 at 06:48
  • Possible duplicate of [How can I remove a commit on GitHub?](https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github) – phd Sep 20 '17 at 10:02

3 Answers3

3

Try doing a git reset to the old commit. Then you can do a git push --force to update the remote. However this would cause some modifications to your project history and your co-worker might have to clone the repo again rather than pulling. Also if unmerged / unstaged paths appear try doing a git stash beforehand.

Isuranga Perera
  • 502
  • 5
  • 17
1

Before rollback to the old commit, please make sure your working tree is clean now by git status.

Then you can rollback to the specified commit (such as commit 2) by the command:

git reset --hard HEAD~2

Note: git reset --hard HEAD~n will reset the current branch to the nth previous commit as HEAD. If you want to reset to commit 3, you can use git reset --hard HEAD~1.

So the commit history will look like:

Commit 2. My co-worker pull commit [1] and pushed what he worked as [2]
Commit 1. I made some binary files, for example: a.bin, b.bin, c.bin and pushed to master branch as commit [1]

To update the changes to remote repo, you can use git push -f to force change the remote repo to the specified commit.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
0

You can recover the binary files from commit [1] with:

$ git show SHA1:path/to/file >path/to/file

Example, provided the "good" version of the binary files is in commit 7bb43ac:

$ git show 7bb43ac:bin/a.bin >bin/a.bin

Do the same for all three 3 of them, then commit and push.

Fabien Bouleau
  • 464
  • 3
  • 11