21

I seem to have ballsed up my git repo by tracking a file, later ignoring it and then deleting it. The thing is, I want the file to be present in a remote repository (the live site), but just don't want to track.

Now my master branch is trying to remove all the files from the repository, which I know will delete them on the remote branch when I push changes... I just want to untrack them, but cannot do that as they're already deleted on master and git rm -r --cached says 'did not match any files'.

How can I untrack these deleted files without removing them from the remote repository?

Martin Petts
  • 503
  • 2
  • 6
  • 15

3 Answers3

32

You just don't want to track a file, but you want to keep the file in the remote repository (non-bare).

Use this git command. After you do this, git stops checking the file for possible modifications.

git update-index --assume-unchanged  <filename>

At any time, you can track again by setting --no-assume-unchaged flag

git update-index --no-assume-unchanged  <filename>

These command do not affect the remote repository.

For more information: http://kar-git.blogspot.in/2012/11/how-to-set-git-to-ignore-few-files-like.html

Karthik Bose
  • 33,556
  • 3
  • 33
  • 43
4

git rm is used to delete files from the repository.

To stop tracking them, you can, after deleting, add them to the .gitignore file in the root of the repository.

heinrich5991
  • 2,694
  • 1
  • 19
  • 26
0

Even if you have untracked a file with git rm, you can still checkout a previous version of that file, e.g.

In your local repo: git rm foo git commit -m 'removed foo' git push origin master

In the remote repository:

git pull origin master // foo will be removed
git checkout abcd1234 -- foo // checkout foo from commit abcd1234 (foo is staged)
git reset HEAD // unstage foo
git status

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo

Then add to .gitignore to untrack

rtn
  • 127,556
  • 20
  • 111
  • 121