'Ignore renamed folder in git
I have a folder let's say,
src/main/resources/basic_abc
For running my code locally, I need to rename it to
src/main/resources/basic
This is a change I want to perform each time I work on this repository. I don't want git to keep on tracking this folder and telling me that basic_abc was renamed to basic. How can I stop git from tracking this rename change?
Furthermore, if I run the command git status, it really gives a messy output since there is a large number of files in this folder.
How could I avoid it?
Solution 1:[1]
I think this can be done by ignoring a directory "locally".
- create a new "basic" directory
- copy all contents in "basic_abc" into it
- goto
\.git\infoin your project directory, open theexcludefile. - add a new line saying
src/main/resources/basic. - execute
git statusagain, you will see git does not consider the new "basic" directory as an untracked file. But you need to synchronize its content with the "basic_abc" directory manually. As long as in the remote repository there is no directory or file named "basic" you are good to go.
The exclude file is for a "local git ignore". It has the same format as the .gitignore file but only works on your machine.
Solution 2:[2]
You could use git rm <folder> --cached - when needed you can simply add the folder again with git add <folder>. Note though that if you do a git commit -a before re-adding the folder, the removal will appear in that commit.
Important notice:
THE --cached argument IS IMPORTANT - WITHOUT THAT, git will DELETE the folder FROM YOUR HARD DISK.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eddie Deng |
| Solution 2 | Programmer |
