You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/src/content/blog/23-gitignore-existing.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ tags: ["Work", "Development"]
8
8
9
9
My colleagues often asking me questions about specific Git functionality. One question which pops up quite often is: How can I remove an existing file from tracking changes by using the `.gitignore` file? Or: How can I ignore future changes to a specific, already existing file in Git?
10
10
11
-
You might have noticed that, if you have an existing file and want to ignore all future changes to it, it doesn't work by simply adding this file to the `.gitignore`.
12
-
That's not a bug of Git, it's actually a feature.
13
-
The `.gitignore` file only works for new changes which will pushed to the tracking index of Git itself for the first time.
14
-
If your file is already tracked for changed by Git, all future changes will also be tracked.
15
-
If a new file is created or a change is made to an untracked file, then Git will take a look at the `.gitignore` file and check if the path matches with one inside the `gitignore` file. If not, it will be adding the changes to the tracking index and from there on they will be tracked.
11
+
You might have noticed that, if you have an existing file and want to ignore all future changes to it, it doesn't work by simply adding this file to the `.gitignore`.
12
+
That's not a bug of Git, it's actually a feature.
13
+
The `.gitignore` file only works for new changes which will pushed to the tracking index of Git itself for the first time.
14
+
If your file is already tracked for changed by Git, all future changes will also be tracked.
15
+
If a new file is created or a change is made to an untracked file, then Git will take a look at the `.gitignore` file and check if the path matches with one inside the `gitignore` file. If not, it will be adding the changes to the tracking index and from there on they will be tracked.
16
16
17
-
So how to solve the problem to ignore future changes to an existing file.
18
-
There are actually 2 options.
19
-
The first one is the simpliest one if you don't need the file at all in your repository.
20
-
Delete the existing file and commit the changes. Afterwards add the file to the `.gitignore` and commit it. Now you can recreate the file and it will no longer be tracked for changes.
21
-
The second option (which is the more interesting one) is by removing the existing file from the index.
17
+
So how to solve the problem to ignore future changes to an existing file.
18
+
There are actually 2 options.
19
+
The first one is the simpliest one if you don't need the file at all in your repository.
20
+
Delete the existing file and commit the changes. Afterwards add the file to the `.gitignore` and commit it. Now you can recreate the file and it will no longer be tracked for changes.
21
+
The second option (which is the more interesting one) is by removing the existing file from the index.
22
22
Remove the existing file from the tracking index with `git rm --cached <file>`. Add now the file to `.gitignore` and commit it. From now on future changes will not be tracked by Git.
0 commit comments