-3

I work in a small team of 5 developers, when I make a git push with one of my changes, the last 10 days of code is disappearing for other developers. Nothing happens to mine. As a team we are unable to find the root cause for this issue.

Checking back in the commit history, doesnt show any of the pushes made in the last 10 days. does anyone have any idea on what could be the root cause for this and how to resolve it?

These are the steps I follow:

git commit (saving local changes) git pull (This was not pulling the exact changes in the remote. My local was not in sync with remote. So I did "git reset --hard origin/master" and that also did not work, later I did "git clean -f". After this, I did a git pull again and got the latest code from remote, then i did a git push.

Now my co-workers do a "git pull"

user2207839
  • 77
  • 1
  • 9
  • 2
    There is some context you're not telling us - doing a `git push` won't directly affect anybody else - they need to (at least) a `git pull` in order to acquire any changes. Could you please illustrate your question with a concrete set of Git commands that were run, and the corresponding output? – Oliver Charlesworth Jan 17 '18 at 19:03
  • 1
    I'd bet dollars to donuts that there is a `-f` flag being passed somewhere. – LightBender Jan 17 '18 at 19:21
  • These are the steps we follow: git commit git pull git Push Then my co-workers: git pull . – user2207839 Jan 17 '18 at 19:22
  • gui or command line? and what exact push command are you using if it's command line? – LightBender Jan 17 '18 at 19:25
  • so your code is disappearing, not the other users'? – LightBender Jan 17 '18 at 19:43
  • 1
    `git push` is not the problem, `git reset` is. See https://stackoverflow.com/q/5788037/1256452 – torek Jan 17 '18 at 22:03

2 Answers2

1

git reset --hard origin/master is the culprit here. Read that command as "reset the index, discard all modified files, check out all the files at origin/master, and move the current branch head to the commit at origin/master." It sounds like you had a merge conflict and you handled it with a knife that is a little too sharp.

Good news is that as long as you've got the original repo you did it in, you can at least get back any files you previously committed. Use git reflog to find the previous version of your commit and use git reset --hard <commit hash>. This will get your current branch back to the state it was in before you started.

No you'll need to integrate the changes on the remote into your current changes (what you did was replace your local changes with the ones on the remote. You have two options for this, git merge and git rebase:

Fetch first to get everything on the remote and update your remote references. (git pull is essentially git fetch and git merge rolled into one command, thought it can be configured to rebase instead). The fetch is non-destructive and allows you to decide exactly how you want to deal with the issue.

If you don't mind a merge commit and a slightly messier history, you can now run git merge origin/master and deal with any conflicts that arise. Then you can push and you'll be up to date.

If you would prefer a straight line of history, you can run git rebase origin/master which will replay your divergent commits on top of the master head. Conflicts may occur at more than one commit on reply, resolve each, stage and run git rebase --continue to resume.

Excellent documentation is available on dealing with conflicts in both situations, so I won't go into detail here.

LightBender
  • 4,046
  • 1
  • 15
  • 31
0

You can do git pull and then checkout to your feature branch. Now you should be able to see all your changes.

ANK
  • 537
  • 7
  • 12