简体   繁体   中英

Undo .gitignore changes

I previously ignored a folder, but now I would like to ignore its content only: How do I remove/modify some entries from my.gitignore file so that git will track them again? I tried updating the gitignore file and adding the folder with git add -f <folder-name> , but it didn't work.

Thank you for your help

What do you mean by ignoring its content only, If you want to track an empty directory?

there is way to make a directory stay (almost) empty (in the repository) is to create a.gitignore file inside that directory that contains these four lines:

# Ignore everything in this directory
*
# Except this file
!.gitignore

Let us say you have one folder named target under the root folder that you added into your.gitignore file. The folder structure is similar to the one below:

-project root
  |- src
       |-- your src files here
  |- target
       |- file1
       |- file2
  |-.gitignore

I assume you want to undo git ignore and selectively ignore file inside the directory that you added to ignore list earlier. Let's suppose you want to add file 1 only from the directory structure above onto git ignore. In this case, edit the.gitignore file to remove the /target/ folder pattern and add a new. gitignore inside the target folder with file1 as content. It should automatically pick up only file2 for tracking.

-project root
  |- src
       |-- your src files here
  |- target
       |- file1
       |- file2
       |- .gitignore - add file1 here
  |-.gitignore - remove /target/ from here

git doesn't track folders, ignoring a folder or ignoring its contents is the same thing when it comes to git.

That said, it should be sufficient to remove the folder-entry from.gitignore to start track things in that folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM