1

I have some changes that I would like to commit.

We use Visual Studio Team Services with git, so some of the attached pictures reflect that. Though, I've used the command line and all of the solutions suggested HERE but still have the issue.

The output window tells me that a handful of files will be overwritten. That's what I want. I didn't make any changes to those files (or, at least, not intentionally!)

My objective is to push my committed changes in order to sync my branch. Please see provided images.

Thanks in advance for any help!

See no untracked changes

These are the two changes I wish to commit

The output window

BoGoodSki
  • 123
  • 1
  • 4
  • 12
  • Nothing worked. So, I just copied the changes I wanted to keep into notepad++ and reset back to a safe point. Thanks for the help. The solutions provided all made sense, and probably should have worked. But I just made a mess of things! :) – BoGoodSki Apr 10 '18 at 14:42
  • Has your problem been solved? – Marina Liu Apr 18 '18 at 08:13

3 Answers3

0

You can use git stash which will save your files hidden from the repo and then you might be able to pull. "Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit." Then try pull. https://git-scm.com/docs/git-stash

If that doesn't work try a

git reset --hard <SOME-COMMIT>

with the SOME-COMMIT being the head of the remote.

sparkitny
  • 1,503
  • 4
  • 18
  • 23
Raph
  • 1
0

The instructions in bold should work in your case:

git stash ( makes your directory clean. Your changes are stored in a local git repo called the stash)

git pull ( Pull the changes from the remote repo)

git stash apply (get back your changes that you saved temporarily)

At this point, you may have some merge conflicts - fix them.

git commit -m 'message' ( Committed the changes )

git push

This has happened because you are probably behind the remote repository in terms of commits, you have to pull the changes inm but git doesn't allow you to do that when files conflict.

When you stash, you are saving all changes you made locally. You can then pull without errors Now getting the changes you made back using stash apply may cause merge conflicts since files changed were the same, you fix those and commit/push! :)

If you have questions feel free to ask!

Achooo
  • 109
  • 6
  • Whenever I try any of the provided solutions, when I get to anything that refers to my changes, such as git stash, I am told that there are no local changes to save. – BoGoodSki Apr 10 '18 at 14:37
0

For the reason why git stop you to push changes to remote repo is that there has commit(s) on the remote repo which you haven't pulled. As you can see there has incoming commits in Sync of the Team Explorer.

And for the reason why the 5 .cs files (you didn't change locally) will be overwritten after git pull, is that the 5 .cs files were changed by others (contains in the incoming commits). That means, the 5 files were changed only for one side, when you pull changes from remote, the 5 files will be merged by recursive strategy.

To keep the five files as the local version, you can checkout after git pull. Detail steps as below:

  1. Get the HEAD commit sha-1 value

    Use the command git log -1 --oneline, assume the HEAD commit sha-1 value is 3ffdb6a.

  2. Pull changes from remote repo

    Execute git pull to pull changes from remote repo.

  3. Switch the 5 .cs files version as the original local repo and push to remote

    Use the command git checkout commit -- filename. Such as:

    git checkout 3ffdb6a -- Senegence Sites/Senegence.Entities.Sites/Distributors/ContactMe.cs
    git checkout 3ffdb6a -- Senegence Sites/Senegence.Entities.Sites/Distributors/CustomerInfo.cs
    git checkout 3ffdb6a -- Senegence Sites/Senegence.Entities.Sites/DistributorsCustomerModel.cs
    git checkout 3ffdb6a -- Senegence Sites/Senegence.Sites.BusinessWorkflows/Products/FilterProductsByCategoryVusinessWorkflow.cs
    git checkout 3ffdb6a -- Senegence Sites/Senegence.Sites.BusinessWorkflows/Products/FilterProductsBySubCategoryVusinessWorkflow.cs
    git commit -m 'recovery the 5 files version as local'
    git push
    

    Note: you can also use wildcards to match the files you want to recovery the version. Such as git checkout 3ffdb6a -- Senegence Sites/Senegence.Entities.Sites/Distributors/*.cs (check all the .cs files in Senegence Sites/Senegence.Entities.Sites/Distributors directory).

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