3

I have a lot of untracked files in my local git repo. Someone accidentially pushed a lot of those untracked files. Now, I want to merge origin/master and I receive:

error: The following untracked working tree files would be overwritten by checkout

I want that untracked files stay in my repo as untracked and I do not want to delete them. The files shouldn't be on origin/master. Is there any elegant way to solve the issue from my side?

3
  • Can you organize the untracked file in a way that they can get added to .gitignore? That way you don't have to worry about them accidentally getting committed in the future. Commented Jul 10, 2013 at 19:08
  • I have done it, but some folks haven't. Commented Jul 10, 2013 at 19:17
  • @LucasSmith if you've got it in your .gitignore, then commit it and everyone will have it. Commented Jul 10, 2013 at 19:39

3 Answers 3

3

You could commit your files to a local branch. You can later restore the files by switching to the other branch and executing git reset HEAD^ (without the --hard option!). Once you have restored the untracked files, you can checkout the (hopefully fixed) master again, and your untracked files should still be there.

But why not revert just the changes from the other guy, first? Of course, it has been pushed, but he can also push the revert. Then you should be fine, again.

Sign up to request clarification or add additional context in comments.

Comments

3

What about the following steps:

On my local master:

git stash --include-untracked git reset --hard origin/master # (origin/master is fetched and it has all of the unnecessary files) git rm {all of the unnecessary files that were pushed accidentially} 

Edit your .gitignore to include all those files you don't want to track.

git add .gitignore git commit git push 

Now I do not have any untracked files on local master and origin/master.

I can get my untracked files back with:

git stash apply 

What do you think?

Comments

2

Clean way is to clone a repo to separate directory, remove untracked files from the repository (or revert the commit), push, remove cloned repository.

1 Comment

or let the one who messed up do that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.