1

I tried to commit my new work with the visual studio 2019 RC4 to GitHub and it failed.

Here is the output: enter image description here

And here is the team explorer:
enter image description here

The reason it failed it seems because I haven't pulled some incoming commits.

But now the problem is the "2019.03.28 morning work" and "2019.03.27 afternoon work" which I code before have so many errors yet. I wanna give up or cover it with the newest one "2019.03.30".

And how can I do it? Would you please help me? Thank you.

102425074
  • 781
  • 1
  • 7
  • 23

1 Answers1

3

What you want to do is called a force push. You are essentially telling the remote repository that you have the correct history of commits and you history is overriding the one on the remote.

This will destroy the commits on the remote repository without any way to recover them. It will also force all of your team members to reset their branch to the remote branch. To avoid losing your commits, you can create a new branch based on the remote branch (assuming your remote is origin and your branch master, you would do git branch features-to-save origin/master).

To delete the commits on the remote repository and replace them with yours, you will have to run (I am unaware if the VS git integration has a force push feature)

git push --force
Simon Doppler
  • 1,918
  • 8
  • 26
  • I would add that if you work in a team on the project and force push, you *need* to communicate it with your colleagues so that if they had the old version, they discard it for the new one, otherwise you will end up with merges and issues you don't want. – padawin Mar 30 '19 at 12:15
  • em....as you said that there is a way force commit. But there is one problem: we don't know whether the visual studio has a GUI for it. I have never use the git without the visual studio, the project is important and I am scaring I will do something wrong with it. – 102425074 Mar 30 '19 at 12:39
  • @padawin Thanks for recommand me. The project is just make by myself, not a teamwork project. – 102425074 Mar 30 '19 at 12:39
  • you can open a git bash in the directory of your project and run `git push --force` from there (most likely right click in the directory -> "open git bash here") – padawin Mar 30 '19 at 12:41
  • well, I found a tutorial how to do it in visual studio now:https://stackoverflow.com/questions/45879374/how-to-make-git-push-origin-force-in-visual-studio-team-explorer @padawin . I did what it said and it worked now! Thank you. – 102425074 Mar 30 '19 at 12:44
  • You are welcome, you can also thank @SimonDoppler, as he came with the original solution :-) – padawin Mar 30 '19 at 12:46