Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get untracked files after a git pull (files were moved on the remote)

Tags:

git

Running a git pull created some untracked files in my local copy. The files were moved on the remote, but the pull didn't remove the files in my working directory. I've spent quite a bit of time researching this, but can't find any similar cases. Is this intended behavior, am I missing something, or both?

Background

I made a patch and sent it to the devs of an open source project, but then I wanted to remove my local commit and git pull the "official" patch once it got committed on the remote. So I did a bunch of "stuff" to reset to the previous official HEAD. "Stuff" means things like git checkout -- <file>, git reset HEAD^, and other commands I cannot remember as I'm new to git and I'm trying to research best practices.

At any rate, after I finally "undid" my commit and did a git pull, I got 66 commits worth of changes, including my patch, and everything looked great. But then git status showed that two files were untracked. I did a gitk <untracked_file1> and I saw that about 20 commits back, the file was moved to another directory. The file now exists in the new location, but instead of deleting the old file, it shows up as untracked.

I tried doing a hard reset by following these instructions, but the files remain untracked. I can do a git clean -f to clear them out, but I'm wondering why the files aren't automatically removed.

like image 888
SO_fix_the_vote_sorting_bug Avatar asked Feb 22 '16 04:02

SO_fix_the_vote_sorting_bug


People also ask

What happens to untracked files when git pull?

git pull doesn't delete uncommitted changes, it doesn't deal with your working directory, any changes or new files will not be touched unless it committed.

Why do I have untracked files in git?

Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .


1 Answers

Ahmed Kamal's answer did not change a thing in my case for a similar problem. I used git clean -f <folder_name> which successfully removed the folder from the files I was tracking.

like image 71
JavaProScript Avatar answered Oct 19 '22 14:10

JavaProScript