6

After git reset --hard HEAD, git pull says: Untracked working tree file ... would be overwritten by merge

any ideas?

I did try a git fetch and git fetch --all already...

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
user1553189
  • 67
  • 1
  • 3
  • Remove the file that would be overwritten? git reset --hard won't remove it because it is untracked (although after the merge it will be tracked...) – antlersoft Apr 25 '13 at 16:57
  • I see. there are a lot of them. I'll continue doing that.. thanks – user1553189 Apr 25 '13 at 17:03
  • this will not work, it is complaining about every file out there including ones that people need. There is no way for me to fix them one by one and then put them all back. – user1553189 Apr 25 '13 at 17:06

5 Answers5

13

If you just want to update your local to the origin's state, you could use described here solution:

$ git fetch origin

$ git reset --hard origin/master
Community
  • 1
  • 1
ephemerr
  • 1,833
  • 19
  • 22
7

you have untracked files. Simply

git stash -u

to stow them away in the stash and get a clean work tree (-u specifies that you want to stash modifications along with new files). After you pull, merge, rebase or whatever, you can

git stash pop

to get them back.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • 1
    I need to ignore un-tracked files that have never been checked in... I want to overwrite any that have been checked in but are out of date. – user1553189 Apr 25 '13 at 17:19
  • I have Git 1.7.0.4.. the stash does not have a `-u` parameter. – user1553189 Apr 25 '13 at 17:23
  • This is the error: `$ git stash -u error: unknown option for 'stash save': -u` – user1553189 Apr 25 '13 at 17:27
  • @user1553189 if you can't update you git version, add an alias for stage-all to be `git add -A && git stash` – Adam Dymitruk Apr 25 '13 at 17:34
  • @user1553189 to add the files that you don't want tracked do `echo *.someextension >> .gitignore`. Then `git add .gitignore`. Your untracked file should not show up anymore by simply having that change to the .gitignore file staged. – Adam Dymitruk Apr 25 '13 at 17:37
  • @AdamDymitruk Sorry, once again the man pages for `-A` are completely confusing to me. It says something about remove files that are no longer in the working tree. I assume that means remove files from staging that are no longer in the working tree. That would only cause problems. – user1553189 Apr 25 '13 at 17:45
  • @user1553189 the `-A` option for `add` is most easily understood as "stage all changes in the work tree". This includes any deletions of tracked files. Remember that it's easiest to think about git if you understand that it stores snapshots of the entire work tree. Whether something was added or deleted is simply the fact that it exists in one version vs another. – Adam Dymitruk Apr 25 '13 at 17:46
  • It is possible to resolve without removing and putting back all those untracked files? – user1553189 Apr 25 '13 at 18:07
2

You need to delete the untracked files. If you want to delete all untracked files, use git clean -fd. Or if you don't want to delete them, use git stash -u to keep it in stash state. To recover from stash state, use git stash pop.

William Seiti Mizuta
  • 7,669
  • 3
  • 31
  • 23
0

You still have untracked files (un git add files). These are not removed by git reset.

If you want to keep them, you could do this:

git add -A
git stash
git pull
git stash apply

stash is like a store where you can add files temporary without commiting them.

Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
0

The reason this occurred in my repository was that another developer had removed a directory / from the main repository and moved it into a submodule. This particular repository had not been used for a long time, so the other develop moved the directory to a submodule between the time I last used the repo and today when the issue occured.

In this case its alright to just remove the offending untracked files.

  • actually you need to do a rm -Rf and then do the git reset --hard HEAD because git will think you want the changes of removing the files added. – Tom Orsi TT Feb 09 '17 at 18:41