0

I'm using a Bitbucket repo with 2 others and we develop a small project together. me and another teammate committed changed in the same time and now none of us can commit, because we would have to pull (not just fetch) beforehand, but that would erase our work. I added the other teammate's code into mine so I have the "correctly merged" version on my side, but to commit I would have to erase the other commit.

Question is, how to do that in VS 2015 team explorer?

Edit

Forcing the latest commit to "take over" the branch is also fine. Is there a way to do that?

agiro
  • 2,018
  • 2
  • 30
  • 62
  • *we would have to pull (not just fetch) beforehand, but that would erase our work* it wouldn't, git would refuse to pull. Or, if you use pull --rebase, probably the correct solution here, it would keep both your commit and the other commits.Not sure if you can do that from within VS, but setting it as the default is a good idea anyway: http://stackoverflow.com/questions/13846300/how-to-make-git-pull-use-rebase-by-default-for-all-my-repositories#13974638 then it has effect in VS as well – stijn Apr 23 '17 at 07:15
  • thanks, I check it out right away – agiro Apr 23 '17 at 07:17
  • Doesn't look promising: https://developercommunity.visualstudio.com/content/problem/5649/setting-pullrebasetrue-in-gitconfig-causes-error-i.html. There are other ways though (stash then pull then apply stash, commit then branch then pull then merge, ...) – stijn Apr 23 '17 at 07:22
  • loving vs :D I'm on 2015 btw, if that makes any difference. – agiro Apr 23 '17 at 07:23

1 Answers1

1

If your project is under version control (in your case, Bitbucket), then it's logical that if a peer is checking some file you're currently working on, and you'll try to check that file in after your peer did, then you'd have to MERGE the files so that you don't overwrite your peer's work.

If you work on two different files, then you won't have to merge since it's two different files, but the best practice is to always get the latest version of the code before checking in, to ensure you don't break the code.

Hope that makes sense. If not, let me know and I'll try to clarify.

Jonathan Perry
  • 2,953
  • 2
  • 44
  • 51
  • Makes sense somewhat, but I edit the question as well, because one thing is still unclear: It is also fine if everyone gets the latest commit. I insert my peer's code into mine so at the end of the day I have the most up to date one. So how to force the latest commit to take over the branch? – agiro Apr 23 '17 at 07:24
  • The branch is always reflecting the latest commit, I'm not sure I understand the question :/ – Jonathan Perry Apr 23 '17 at 07:36
  • A mate has committed something 16 hours ago, I committed something 13 hours ago and then 8 mins ago. I copy pasted his code into mine, so I have the ultimate version. I try to push my changes but it says _it would be a non fast forward update_ so it doesn't let me push until I pulled. I fear that pulling would erase my work. I just wish that my work is on the branch. – agiro Apr 23 '17 at 07:39
  • You shouldn't copy-paste his code, you rather should get the latest version and that would bring your friends' code to you. By copy-pasting you might be confusing the version control system by thinking you're using a wrong version of code. AVOID copy-pasting, just use the version control system and you should be fine. (Get latest code, merge if necessary, and check-in) – Jonathan Perry Apr 23 '17 at 07:42
  • I'll keep and eye on that. The conflict was that we were working on different files, so at some point, both our codes were the "latest", just other files modified. – agiro Apr 23 '17 at 07:44
  • So after all, shall I just pull, then push? Will that keep my stuff intact? – agiro Apr 23 '17 at 07:50
  • If you get the latest version before checking in your own code, you shouldn't overwrite anything. – Jonathan Perry Apr 23 '17 at 07:52