0

I have a fullstack app and the folder structure as shown below:


my-app
  |_____ .git
  |_____ backend
  |_____ frontend 
  |_____ .gitignore  

As I want to keep all project files in a single repo on GitHub, I init my .git repo in the root folder (there is no .git or .gitignore in the project directories (backend or frontend). However, although I included the target folders and log directory in my backend project, I still see these directories as changes when I execute git status as shown below:

modified:   .gitignore
modified:   backend/logs/application.log
modified:   backend/target/account-api-0.0.1-SNAPSHOT.jar
modified:   backend/target/classes/com/company/common/Constants.class

I tried various combinations by following https://www.atlassian.com/git/tutorials/saving-changes/gitignore. But does not make any sense. Here is related part of my .gitignore. I am not sure if I should restart command Window or make anything the changes take effect.

target/
logs/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

...

So, how should I update related ignore files and locations when I move .gitignore from:

from backend folder --> to my-app folder

I also tried to add backend, or /backend to some fields, but still no changes. Of course it would be better use a wildcard to cover all the related folders e.g. target. Any idea?

  • 1
    Does this answer your question? [How do I make Git forget about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – 1615903 Feb 22 '23 at 06:25
  • @1615903 No. What about the other issue? How should I update the folder and file locations when I move .gitignore file from backend to project root? In this case, how can I use a wildcard to update locations? For example, formerly it was `target`, but now it is `backend/target`. Any idea? –  Feb 22 '23 at 06:42
  • No need to change anything, since you are using unanchored pattern already. – 1615903 Feb 22 '23 at 06:43
  • 1
    `git status` reports the files as modified, which means they are already tracked. `.gitignore` only works for untracked files. See the linked question for help on that. – 1615903 Feb 22 '23 at 06:44
  • @1615903 And the answers are more than 10 years old and I am not sure which one is the most useful (I do not make anything wrong by trying each of them). –  Feb 22 '23 at 06:46
  • tracked/untracked file issue is a good point, thanks. On the other hand, I am also wondering, although I open only backend project in IntelliJ IDEA, it also tracks frontend. So, is is a correct track or something e.g. cache? I mean, in order to manage git commits, stages, pushes on IntelliJ IDEA, should I open the project from project root where .git folder is located? Or does it not make any sense even I open the project on backend folder where no .git folder is located? –  Feb 22 '23 at 06:49
  • @1615903 Any reply pls regarding to my last comments? –  Feb 22 '23 at 06:56
  • Please don't additonal practically unrelated questions as comments, but add a new question. A Git repository is always tracking the full worktree. So even if you only open a subfolder as project in the IDE, the repository still contains the whole worktree. If you want to track the projects individually, you need to have them in separate Git repositories. – Vampire Apr 13 '23 at 12:05

0 Answers0