0

So I am using Github very infrequently because I am the only one working on a project. After about two weeks, I decided I should probably push some code to Github. When I pushed the code, it set the files I am working on back to where they were two weeks ago (I am using Xcode and it basically erased everything from the last two weeks) and didn't push any of the changes to Github.

How can I undo this?

Thanks

connorvo
  • 761
  • 2
  • 7
  • 21
  • Reverting a commit might help? https://stackoverflow.com/questions/927358/how-to-undo-the-last-commits-in-git – Tatsuya Yokota Nov 14 '17 at 19:53
  • Can you show the specific sequence of `git` commands/operations you used? I find it difficult to imagine that a `git push` would have mutated your local repo like this. – Oliver Charlesworth Nov 14 '17 at 19:54
  • So I was on a separate branch initially so I added and committed to that branch, switch to master branch, added, committed, push – connorvo Nov 14 '17 at 19:57
  • So I had it all committed but not pushed to the initial branch I was on. So I pushed it to that branch and was able to get it that way, but it is nowhere to be found on my master branch and my local code was reverted to last commit to master branch – connorvo Nov 14 '17 at 20:02

1 Answers1

0

I could be wrong. But if you were on a separate branch and pushed and committed those changes you worked on the last two weeks. Then switch to master and pushed you might want to switch back to your older branch and reload your project to get those new changes.

If you want your master to reflect these changes you are going to need to merge the two branches

skrusetvt
  • 261
  • 3
  • 17
  • Yeah, that is what I ended up doing. – connorvo Nov 14 '17 at 20:08
  • So if you are on a branch and want to push something to master branch, it doesn't let you switch branches without committing the changes. Does this mean you will always have to push to the branch you are on and then merge with master instead of being able to just switch to master and push? – connorvo Nov 14 '17 at 20:12
  • I believe if you want to switch branches you should always 'push'. In my experience with Git, I always 'pull' before 'push' also. If you merge with your master branch with your branch in the remote repository. Then switch to your branch and never pull, your local repository will never reflect those changes. And then if make changes and try to push without pulling, it will lead to conflicts. – skrusetvt Nov 14 '17 at 20:29