简体   繁体   中英

How do you NOT add untracked files in git?

I was messing around and now I don't want to commit these files. How do I remove these from being committed?

git status 
On branch sign-up
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    HEAD
    description
    hooks/
    info/
    sample_app/

nothing added to commit but untracked files present (use "git add" to track)

If you wish to have git not track these files again, add them to .gitignore and git will ignore these files and/or directories. Read more on ignoring files in git here .

However, you can choose to not add them to .gitignore if you will be committing them in the future. Git will continue to raise this warning until you choose to track or ignore them.

Right now those files will not be committed as they are untracked and thus git will simply ignore them.

I your case git status simply informs you that you could track (and thus add those files to your next commit) should you wish to.

If you do not want these files to be added by accident, the first option is adding them to your .gitignore file ( details in Pro Git ). A simple one of your .gitignore may be:

HEAD
description
hooks/
info/
sample_app/

Please note that you should add the .gitignore file to your repository if you do not need these files.


The files you mentioned are untracked . as output of your git status command says, theses files are not added to commit. ( nothing added to commit but untracked files present (use "git add" to track)

Git uses a track-stage-commit cycle to keep track on your files ( details in Pro Git ). Files will only be committed to Git repository when they are staged .

As my personal practice, I usually begin with the .gitignore file in GitHub provided ones, then I add some repo specific directories and files to the top of gitignore file with comments, so that I'll get a clear logic of what is ignored in the repository.

# Repo specific settings
wiki/
test/

# Object files
*.o
*.ko

# Libraries
*.lib
*.a
*.la
*.lo

You are currently working with new files, so they are in the file status of untracked .

  • This means that Git actually sees your new files, but it doesn't take care of them until you git add

  • After you do a git add your files move into an unmodified file status. The reason it is unmodified is because this is a new file with no previous version. Basically Git has never tracked any changes before.

Here is a great link to get familiar with File Status Lifecycle with Git. Git File Status Lifecycle .

If you wish to have git not track these files again, add them to .gitignore eg a sample .gitignore file can look like one below for a Android Studio project

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties


#Eclipse
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
YourProjetcName/.gradle/
YourProjetcName/app/build/
*/YourProjetcName/.gradle/
*/YourProjetcName/app/build/

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/
/build
build/
*/build/
*/*/build/
*/*/*/build/
*.bin
*.lock
YourProjetcName/app/build/
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
.gradle/
app/build/
*app/build/

# Local configuration file (sdk path, etc)
local.properties
/YourProjetcName/build/intermediates/lint-cache/api-versions-6-23.1.bin
appcompat_v7_23_1_1.xml
projectFilesBackup
build.gradle
YourProjetcName.iml
YourProjetcName.iml
gradlew
gradlew.bat
local.properties
settings.gradle
.gradle
.idea
android
build
gradle

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