I have a github
repository, which I checked out locally.
environment.local-dev.ts
file. (It usually points to localhost, but as I don't have local api repository installed, I updated file to point to my colleagues local api)I searched for two options :
.gitignore
. But the problem is, I will still see .gitignore
, which I might commit accidently..git/info/exclude
. I did this, but I am still seeing the changed files when I do git status
The Github repository, I am working on is already created by someone else. So cannot change the initial configuration. Also other people are working on the same repository so cannot commit changes which might affter other people negatively.
So, the problem is to find a way to not commit
files which are being tracked by git
. Is there a way to do this ?
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.
To ignore files in your repository with GitHub Desktop go to the Repository menu and select Repository Settings… With the Repository Settings pop-up open, click the Ignored Files tab. Here you will be able to add file names, directory names, or patterns for Git to ignore in your repository.
A local . gitignore file is usually placed in the root directory of a project. You can also create a global . gitignore file and any entries in that file will be ignored in all of your Git repositories.
EDIT: as pointed by @Philippe skip-worktree
would be more appropriate than assume-unchanged
. In this answer, everything is the same but you just switch the option.
.gitignore
and .git/info/exclude
are only to exclude untracked files.
To ignore local modifications of tracked files, you can use git update-index --assume-unchanged FILES...
.
But there is a risk to forget modifications that need to be committed in the file.
To get the modification visible again: git update-index --no-assume-unchanged FILES...
.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
$ git update-index --assume-unchanged file
$ git status
On branch master
nothing to commit, working tree clean
$ git ls-files -v
h file
$ git update-index --no-assume-unchanged file
$ git ls-files -v
H file
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
You can define some aliases:
[alias]
forget = update-index --assume-unchanged
unforget = update-index --no-assume-unchanged
forgotten = ! git ls-files -v | grep ^[a-z]
A better way would be to have an local ignored configuration overwritting file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With