Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell git to ignore all further edit to a single file without removing it from the repo

I have forked a project on github and started messing around with it on my own machine, I want to commit the changes I have made back to my fork on github but without commiting the changes I have made to the .cfg file, since this contains things like db password etc

like image 834
Gabriel Baker Avatar asked Nov 06 '10 17:11

Gabriel Baker


People also ask

How do I ignore changes to a file in Git?

In the Git Changes window, right-click any changed file that you want Git to ignore and choose Ignore this local item or Ignore this extension. Those menu options don't exist for tracked files.

How do I tell Git to ignore a file?

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 would you best force Git to not track changes a file or directory?

What you probably want to do is this: git update-index --skip-worktree . (The third option, which you probably don't want is: git rm --cached .

Which command can you remove a file from Git without removing it from file system?

Using the git rm –cached Command However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched.


1 Answers

Use this:

git update-index --skip-worktree path/file.cfg 

And to restore:

git update-index --no-skip-worktree path/file.cfg 

Lastly, if you want to list files that are marked with skip-worktree:

git ls-files -v | grep ^S | awk '{print $2}' 

To simplify, you can make an alias for that in your $HOME/.gitconfig:

[alias]     ls-ignored-changes = !git ls-files -v | grep ^S | awk '{print $2}' 

Then you can type just git ls-ignored-changes. It even works with auto-completion if you have the git-completion in place (for bash, tcsh, zsh).

like image 122
jweyrich Avatar answered Sep 20 '22 11:09

jweyrich