1

I just started learning Git & Ruby on Rails and from the cmd prompt on my Windows 7 machine, I accidentally did a git add -A under my C:\Users\myusername.

All my files were added, but are untracked locally on Git. Obviously, I don't want to delete them – they are ALL my user files. However, since it is an empty repo, I can't find how to untrack them and clean up git. git status and git log responses are below.

PS C:\Users\myusername> git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
***All files listed***
nothing added to commit but untracked files present (use "git add" to track)

PS C:\Users\myusername> git log
fatal: bad default revision 'HEAD'
eckes
  • 64,417
  • 29
  • 168
  • 201
  • I you haven't commited your local changes, can't you just delete the `.git` folder from `c:/Users/yourusername`. – Cyclonecode Aug 16 '12 at 17:55
  • I don't have a .git folder c:/Users/yourusername there in windows explorer. Furthermore, I do have a Rails project in Git that I've started under PS C:\Users\myusername\rails_projects\first_app>. I would like to not have to uninstall git entirely, but would just like to undo the git add -A and the untracked files. As I've already set git up with GitHub, SSH, and Heroku. – user1603937 Aug 16 '12 at 18:00
  • @user1603937 It's probably invisible. If you did what you wrote it should be there. – Andrzej Gis Aug 16 '12 at 18:04
  • My git program folder is C:\RailsInstaller\Git, How do I find and just untrack the files in the empty repository C:\Users\myusername\ locally without deleting my git program folder? Or find the specific .git folder referenced above? Thank you again for your help. – user1603937 Aug 16 '12 at 18:05
  • Can I do a git reset --hard or git rm --cached under C:\Users\myusername> without deleting my files? Will this untrack them? – user1603937 Aug 16 '12 at 18:14
  • Are you sure you did `git add -A`? If that were the case, `git status` should show all your files under "Changes to be committed:" and labelled with "new file:", but your `git status` shows everything as "Untracked files", and additionaly states "nothing added to commit...". That doesn't seem consistent... – twalberg Aug 16 '12 at 18:37

3 Answers3

1

Your posted output of git status does not match what you're describing:

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
***All files listed***
nothing added to commit but untracked files present (use "git add" to track)

This message means:

  • yes, we are in a Git repo (On branch master)
  • we haven't committed anything yet (Initial commit)
  • there is a bunch of files present in the directory that doesn't belong to your Git repo yet (Untracked files followed by ***All files listed***)
  • and the index is clean (nothing added to commit)

If this is really the case, then simply delete the .git folder present on C:\Users\myusername (yes, there is one) and you're done.

But what you're writing is that you did a git add -A. In that case, ***All files listed*** should appear under Changes to be committed:. Nonetheless, also in that case removing your .git folder will do no harm to your files. It will simply delete the repo information.

eckes
  • 64,417
  • 29
  • 168
  • 201
1

Do nothing

Assuming you want to have a git repo in your home dir, you need do absolutely nothing, because:

C:\Users\myusername> git status
# On branch master
#
# Initial commit

This indicates that you have no current git history - your git repo is empty

#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
***All files listed***

This is listing files that exist, are not already tracked and are not ignored - it's listing everything because everything is an untracked file.

git add -A

You have not (going by the output of git status in the question) ran this command, at least not on this repo. If you do run this command the output from git status will be quite different. You will see:

C:\Users\myusername> git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage
***All files listed***

Read carefully the last two comment lines of this, and the output you have in the question. "Changes to be committed" and "Untracked files" are very, very different in meaning. In the question there is nothing added. In the above - everything is staged to be committed - and can be unstaged with git rm -r --cached .

Tracked files

Tracked files are files that git is monitoring for changes etc. UN tracked files is everything else - what you have in the question is probably a misunderstanding. You can demonstrate this to yourself with this example sequence:

cd C:\Users\myusername
rmdir /S .git
git status
# error message
git init
git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
***All files listed***
Community
  • 1
  • 1
AD7six
  • 63,116
  • 12
  • 91
  • 123
0

Just remove C:\Users\myusername\.git folder. Note that it may be invisible.

EDIT

This is probably what you need:

git rm -r --cached .

This will not modify your filesystem.

Andrzej Gis
  • 13,706
  • 14
  • 86
  • 130
  • My git program folder is C:\RailsInstaller\Git, How do I find and just untrack the files in the empty repository C:\Users\myusername\ locally without deleting my git program folder? Or find the specific .git folder referenced above? Can I do a git reset --hard or git rm --cached under C:\Users\myusername> without deleting my files? Will this untrack them? Thank you again for your help – user1603937 Aug 16 '12 at 18:16
  • You could also try doing `git reset HEAD C:/Users/myusername` – Cyclonecode Aug 16 '12 at 18:19
  • I get the response... fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions – user1603937 Aug 16 '12 at 18:25
  • So just to make sure git rm -r --cached will not delete/remove my files from my C: drive? – user1603937 Aug 16 '12 at 18:26
  • @user1603937 no, you will be fine :) PS note there is a [.] sign after cached – Andrzej Gis Aug 16 '12 at 18:27
  • the response...PS C:\Users\coolhandluke> git rm -r --cached . fatal: pathspec '' did not match any files there has to be a way to rollback this git add -A? Or can I just leave those files untracked @ C:/Users/myusername? – user1603937 Aug 16 '12 at 18:34
  • @user1603937 You can leave it as it is. I've just realized that your git status indicates there was nothing added to git. One more thing. Can you please paste the output of 'git init' in some empty directory? (with whole path) – Andrzej Gis Aug 16 '12 at 18:47