agent.smith
agent.smith

Reputation: 9416

Untrack files from git temporarily

I have setup a local git on my machine. When I initialized git, I added pre-compiled libs and binaries. However, now during my development I don't want to check in those files intermittently. I dont want to remove these files from repo. Is there any way to not keep a track of these files till I complete my development. (I think I can not use .gitignore as it works only for those files which are not in git. I want to temporarily disable tracking of files.)

Upvotes: 563

Views: 607556

Answers (10)

N Jedidiah
N Jedidiah

Reputation: 1783

Run

git rm -r --cached file_to_git_ignore

Then go to your gitignore file and add path_to_file_to_git_ignore

Good luck

Upvotes: 5

AlainD
AlainD

Reputation: 6587

An alternative to assume-unchanged is skip-worktree. The latter has a different meaning, something like "Git should not track this file. Developers can, and are encouraged, to make local changes."

In your situation where you do not wish to track changes to (typically large) build files, assume-unchanged is a good choice.

In the situation where the file should have default contents and the developer is free to modify the file locally, but should not check their local changes back to the remote repo, skip-worktree is a better choice.

Another elegant option is to have a default file in the repo. Say the filename is BuildConfig.Default.cfg. The developer is expected to rename this locally to BuildConfig.cfg and they can make whatever local changes they need. Now add BuildConfig.cfg to .gitignore so the file is untracked.

See this question which has some nice background information in the accepted answer.

Upvotes: 5

divya d
divya d

Reputation: 165

To remove all Untrack files. Try this terminal command

 git clean -fdx

Upvotes: -1

Dinesh Vaitage
Dinesh Vaitage

Reputation: 3183

Use following command to untrack files

git rm --cached <file path>

Upvotes: 67

prime
prime

Reputation: 15564

Not an answer to the original question. But this might help someone.

To see the changes you have done (know which files are marked as --assume-unchanged)

git ls-files -v

The resulted list of files will have a prefix with one character (ex : H or h) If it is a lowercase (i.e. h) then the file was marked --assume-unchanged

Upvotes: 13

cajuuh
cajuuh

Reputation: 3827

you could keep your files untracked after

git rm -r --cached <file>

add your files with

git add -u

them push or do whatever you want.

Upvotes: 368

Vraj Pandya
Vraj Pandya

Reputation: 621

I am assuming that you are asking how to remove ALL the files in the build folder or the bin folder, Rather than selecting each files separately.

You can use this command:

git rm -r -f /build\*

Make sure that you are in the parent directory of the build directory.
This command will, recursively "delete" all the files which are in the bin/ or build/ folders. By the word delete I mean that git will pretend that those files are "deleted" and those files will not be tracked. The git really marks those files to be in delete mode.

Do make sure that you have your .gitignore ready for upcoming commits.
Documentation : git rm

Upvotes: 5

Andy
Andy

Reputation: 46324

git update-index should do what you want

This will tell git you want to start ignoring the changes to the file
git update-index --assume-unchanged path/to/file

When you want to start keeping track again
git update-index --no-assume-unchanged path/to/file

Github Documentation: update-index

Upvotes: 888

Eric Spreen
Eric Spreen

Reputation: 341

The git-book mentions this in section 2.4: "Undoing Things". Basically, what you have to do is reset the state of the index for some files back to the HEAD state, that is to the state of the latest checkout (or commit). This undoes staging the file to the current index. The command for this task is git reset.[1]

So, the command you have to execute is:

git reset HEAD /path/to/file

The newer versions of git (I believe since 1.6 or so) gives this command (and many more) as a tip when executing git status. These versions are very user-friendly. A personal tip: if you are only staging a few files, use git add -i. This will launch the interactive staging tool, which makes thing particularly easy. Also, I highly recommend reading the book, as it is very explicit on the use of git in practical situations.

[1] http://www.git-scm.com/book

Upvotes: 8

Tekkub
Tekkub

Reputation: 31695

git rm --cached

However, you shouldn't be committing compiled binaries and external dependancies in the first place. Use a tool like Bundler to pull those in instead.

Upvotes: 118

Related Questions