4

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) 
4
  • 1
    Git only commits files in "staging", which are files you've added yourself. The "untracked files" are files you've changed, but not added to staging. They will not be committed, but since they are changed, git will continue to let you know about them (unless you explicitly ignore them in .gitignore). Commented May 21, 2016 at 22:16
  • 1
    Those files are suspiciously similar to those found in the .git/ directory of a Git repository. Did you perhaps do a git init inside a .git directory? Commented May 22, 2016 at 0:23
  • 2
    @SteveD That's all correct, except they're not "changed". Git doesn't track the files, so it cannot know if they're changed or not. They're simply files and directories Git is not tracking. Commented May 22, 2016 at 0:25
  • @schwern: my mistake, was thinking of files previously committed. Commented May 22, 2016 at 0:31

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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 

2 Comments

Remember if you want to add new files to .gitconfig file even if it is marked to be ignored, you to use the git command git add -f <file name>
Exactly. I'd also like to note that you may find some file been tracked by Git, then adding them to .gitignore doesn't remove them from tracking. Use git rm [--cached] <file name> to remove file from track by Git, then .gitignore will work properly to prevent these files to be tracked again.
0

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.

Comments

-1

If you wish to have git not track these files again, add them to .gitignore e.g. 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 

Comments