Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with .git/info/exclude too late

Tags:

I usually do this:

git init git add . git commit . 

And then I realize that it's about to add my nbproject directory, which I want excluded/ignored. Sometimes, I even check in this directory. Had I added it to .git/info/exclude before running git add., everything works fine (it's excluded).

So then I modify .git/info/exclude and then it's too late. git no longer respects changes to .git/info/exclude.

So the questions are:

  1. How can I get git to take up the changes in the exclude file in the checkin? (I tried running git add . again, which doesn't help)
  2. Let's say I check in a directory (or file) that I want excluded. What is the least number of steps to get to the state I want (with the file excluded).
like image 804
Dan Rosenstark Avatar asked Jul 21 '09 12:07

Dan Rosenstark


People also ask

How to ignore already tracked files in git?

Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.

How to git ignore after commit?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

How to exclude files from git commit?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

What is git info exclude?

git/info/exclude . This file is your own gitignore inside your local git folder, which means is not going to be committed or shared with anyone else. You can basically edit this file and stop tracking any (untracked) file.


1 Answers

To remove a file that you have added but not committed, use a command like this:

git rm --cached file.to.remove 

This will remove the file from the index, but not touch the file on disk.

To remove a file (or files) from the most recent commit, use the above git rm --cached command followed by git commit --amend.

like image 173
Greg Hewgill Avatar answered Sep 22 '22 15:09

Greg Hewgill