The following untracked working tree files would be overwritten by merge, but I don't care

前端 未结 16 1022
挽巷
挽巷 2020-12-02 03:37

On my branch I had some files in .gitignore

On a different branch those files are not.

I want to merge the different branch into mine, and I don\'t care if t

相关标签:
16条回答
  • 2020-12-02 04:00

    In my case when I had this problem. I had a local file that I had renamed on the remote.

    When trying to git pull Git told me the new filename was not tracked -- which it was on the remote although it didn't yet exist on local.

    Because there was no instance of it locally I couldn't do git pull until I did git rm on the old filename (which wasn't obvious at first because of my stupid idea of renaming it).

    0 讨论(0)
  • 2020-12-02 04:04

    The problem is that you are not tracking the files locally but identical files are tracked remotely so in order to "pull" your system would be forced to overwrite the local files which are not version controlled.

    Try running

    git add * 
    git stash
    git pull
    

    This will track all files, remove all of your local changes to those files, and then get the files from the server.

    0 讨论(0)
  • 2020-12-02 04:06

    The problem is when we have incoming changes that will merge untracked file, git complains. These commands helped me:

    git clean -dxf
    git pull origin master
    
    0 讨论(0)
  • 2020-12-02 04:09

    In addition to the accepted answer you can of course remove the files if they are no longer needed by specifying the file:

    git clean -f '/path/to/file/'
    

    Remember to run it with the -n flag first if you would like to see which files git clean will remove. Note that these files will be deleted. In my case I didn't care about them anyway, so that was a better solution for me.

    0 讨论(0)
  • 2020-12-02 04:09

    For those who don't know, git ignores uppercase/lowercase name differences in files and folders. This turns out to be a nightmare when you rename them to the exact same name with a different case.

    I encountered this issue when I renamed a folder from "Petstore" to "petstore" (uppercase to lowercase). I had edited my .git/config file to stop ignoring case, made changes, squashed my commits, and stashed my changes to move to a different branch. I could not apply my stashed changes to this other branch.

    The fix that I found that worked was to temporarily edit my .git/config file to temporarily ignore case again. This caused git stash apply to succeed. Then, I changed ignoreCase back to false. I then added everything except for the new files in the petstore folder which git oddly claimed were deleted, for whatever reason. I committed my changes, then ran git reset --hard HEAD to get rid of those untracked new files. My commit appeared exactly as expected: the files in the folder were renamed.

    I hope that this helps you avoid my same nightmare.

    0 讨论(0)
  • 2020-12-02 04:10

    You can try command to clear the untracked files from the local

    Git 2.11 and newer versions:

    git clean  -d  -f .
    

    Older versions of Git:

    git clean  -d  -f ""
    

    Where -d can be replaced with the following:

    • -x ignored files are also removed as well as files unknown to Git.

    • -d remove untracked directories in addition to untracked files.

    • -f is required to force it to run.

    Here is the link that can be helpful as well.

    0 讨论(0)
提交回复
热议问题