Untracked files prevent checkout как исправить

I'm trying to merge a branch with the master, so I checked out the master but now it won't let me do the merge: Untracked Files Prevent Checkout Move or commit them before checkout .idea/vcs.xml ...

I’m trying to merge a branch with the master, so I checked out the master but now it won’t let me do the merge:

Untracked Files Prevent Checkout
Move or commit them before checkout
.idea/vcs.xml

I can’t move or delete the file, because it will disengage the VCS from this project
I can’t commit it because it’s not an option when I try to commit
I can’t switch to the branch to see what I can do from that end, because I get the same error message.

How can I fix this and how can I prevent it from happening again? Do I need a .gitignore file that is set up to exclude everything from the .idea folder?

asked Nov 22, 2019 at 20:50

fudge's user avatar

2

The branch you’re trying to merge has this file checked into it, but the master branch has untracked (and possibly in .gitignore). When you’re trying to merge the other branch, Git prevents you from overwriting those files because you might care about them (after all, one side has them tracked).

You have some options:

  • Delete the file and merge, which will include the version from the branch you’re trying to merge.
  • Change the branch (or have the author of the branch change the branch) to not include the file you don’t want to override and make sure it’s in .gitignore. If this is a file specific to a given editor, it probably doesn’t belong in version control, since different people use different editors and different settings.
  • Save the file to somewhere else, merge, and then determine what to do after you see the result of the merge.

answered Nov 22, 2019 at 23:20

bk2204's user avatar

bk2204bk2204

58.3k5 gold badges63 silver badges86 bronze badges

1

Expand the .idea folder and right-click on vxs.xml and have the IDE add that file to to .gitignore. Then you should be able to Pull from GitHub.

answered May 20, 2020 at 12:28

Sam's user avatar

SamSam

9599 silver badges13 bronze badges

One thing that worked for me was that in pycharm, when it asks for smart checkout, don’t use the smart checkout. go through and merge manually.

Dharman's user avatar

Dharman

29.3k21 gold badges80 silver badges131 bronze badges

answered Jan 21, 2021 at 17:05

Emanuele Ebrahimi's user avatar

You should:

  1. create a .gitignore file in local project’s folder,

  2. If you use PHPstorm, press «NO» button, when PHPstorm ask you «add .gitignore file to Git?»

  3. fill it:

    /.gitignore

    /.idea/*

Eric Aya's user avatar

Eric Aya

69.1k35 gold badges179 silver badges250 bronze badges

answered Dec 19, 2022 at 10:38

Andrews32's user avatar

Andrews32Andrews32

271 silver badge4 bronze badges

I’m trying to merge a branch with the master, so I checked out the master but now it won’t let me do the merge:

Untracked Files Prevent Checkout
Move or commit them before checkout
.idea/vcs.xml

I can’t move or delete the file, because it will disengage the VCS from this project
I can’t commit it because it’s not an option when I try to commit
I can’t switch to the branch to see what I can do from that end, because I get the same error message.

How can I fix this and how can I prevent it from happening again? Do I need a .gitignore file that is set up to exclude everything from the .idea folder?

asked Nov 22, 2019 at 20:50

fudge's user avatar

2

The branch you’re trying to merge has this file checked into it, but the master branch has untracked (and possibly in .gitignore). When you’re trying to merge the other branch, Git prevents you from overwriting those files because you might care about them (after all, one side has them tracked).

You have some options:

  • Delete the file and merge, which will include the version from the branch you’re trying to merge.
  • Change the branch (or have the author of the branch change the branch) to not include the file you don’t want to override and make sure it’s in .gitignore. If this is a file specific to a given editor, it probably doesn’t belong in version control, since different people use different editors and different settings.
  • Save the file to somewhere else, merge, and then determine what to do after you see the result of the merge.

answered Nov 22, 2019 at 23:20

bk2204's user avatar

bk2204bk2204

58.3k5 gold badges63 silver badges86 bronze badges

1

Expand the .idea folder and right-click on vxs.xml and have the IDE add that file to to .gitignore. Then you should be able to Pull from GitHub.

answered May 20, 2020 at 12:28

Sam's user avatar

SamSam

9599 silver badges13 bronze badges

One thing that worked for me was that in pycharm, when it asks for smart checkout, don’t use the smart checkout. go through and merge manually.

Dharman's user avatar

Dharman

29.3k21 gold badges80 silver badges131 bronze badges

answered Jan 21, 2021 at 17:05

Emanuele Ebrahimi's user avatar

You should:

  1. create a .gitignore file in local project’s folder,

  2. If you use PHPstorm, press «NO» button, when PHPstorm ask you «add .gitignore file to Git?»

  3. fill it:

    /.gitignore

    /.idea/*

Eric Aya's user avatar

Eric Aya

69.1k35 gold badges179 silver badges250 bronze badges

answered Dec 19, 2022 at 10:38

Andrews32's user avatar

Andrews32Andrews32

271 silver badge4 bronze badges

This could also happen due to a case change on the filename. I had the same problem and this is what solved it for me.

git config core.ignorecase true

True for Mac or PC.

Alternative solutions at: The following untracked working tree files would be overwritten by checkout

Without a complete picture of the repo, what follows is more of a guess than anything else, but it might explain the situation. Let’s say your history looks as follows:

A -- C [origin/master]
   
   B [HEAD, master]

You write:

This file has been coming up constantly and when I remove it from file system, git will say I removed this file, while in the other messages, it says it is untracked.

I’m guessing you may have run

git rm --cached <file-in-question>

and committed that deletion in commit B; therefore, the file is no longer tracked in your local repo and but it’s still present in your working tree.

In the meantime, the upstream branch received commit C from one of your collaborators, in which <file-in-question> was not removed from version control. What you’re attempting to effect with

git pull --rebase

is something like this:

 A -- C [origin/master]
        
        B' [HEAD, master]

However, as the message says,

The […] untracked working tree [file] would be overwritten by checkout

Indeed, rewinding commit C (in order to replay B on top of it) would result in the revision of <file-in-question> (from commit C) to be checked out in your working tree, in which an untracked file of the same name already exists. The contents of that untracked file may be valuable; you may not want that file to be overwritten by a another version of it. Therefore, Git stops in its track and tells you what’s wrong.

Edit: Here is a baby example that reproduces the situation…

cd ~/Desktop
mkdir test
cd test
git init
touch README.md
git add README.md
git commit -m "add README"

# simulate a remote branch moving ahead by one commit
# (that doesn't remove the README)
git checkout -b origin_master
printf "This is a README.n" > README.md
git add README.md
git commit -m "add description in README"

# remove the README and create a new commit on master
git checkout master
git rm --cached README.md
git commit -m "remove README"

# simulate an attempt to rebase master to its "upstream" branch, origin_master
git rebase --onto origin_master master

That last command spews out the following:

First, rewinding head to replay your work on top of it...
error: The following untracked working tree files would be overwritten by checkout:
    README.md
Please move or remove them before you can switch branches.
Aborting
could not detach HEAD

I suggest you run

git fetch
git log --stat origin/master..master -- <file-in-question>

to check whether something like that happened.

Remove all untracked files (carefull):

git clean  -d  -fx ""

Понравилась статья? Поделить с друзьями:
  • Unsupported personality pcl ошибка
  • Unsupported partition table как исправить windows 7
  • Unsupported operand type s for str and int как исправить
  • Unsupported operand type s for int and str python ошибка
  • Unrecoverable playback error invalid argument