0

I mistakenly ran 'git init' followed by 'git add -A' on a main folder (named "workspace"). I intended to 'cd' down into a new project folder (named "authentication") before running these commands.

The issue is, this main folder "workspace" already had numerous project subfolders that were individually in Git beforehand. The main folder was not previously under Git, nor ever meant to be. Fortunately, I have NOT ran 'git commit' on the main folder.

How do I safely reverse the 'git add -A' on the main folder, as well as revert the 'git init' command on the main folder, WITHOUT affecting all the subfolder projects that are to remain individually under version control (Git)?

BryanH
  • 3
  • 4

2 Answers2

2

If your main folder workspace was not under Git before, just delete the folder workspace/.git:

rm -r workspace/.git

If it was under Git, git init will have pretty much no effect. The opposite action of add is reset:

git reset
padawin
  • 4,230
  • 15
  • 19
  • Yes I'll clarify, the main folder was not under Git before. I have updated my original comments to make this more clear. – BryanH Apr 04 '19 at 03:50
  • Then just remove the directory `workspace/.git` that `git init` created, and you will be sorted. – padawin Apr 04 '19 at 07:35
  • This command didn't seem to work for me. Here's what I got: rm: cannot remove ‘workspace/.git’: No such file or directory – BryanH Apr 07 '19 at 04:05
  • if you go in the `workspace` directory, and run `git status`, what do you get? – padawin Apr 07 '19 at 08:26
  • So I get `On branch master No commits yet Changes to be committed: (use "git rm --cached ..." to unstage)`. Then it lists `new file:` followed by all the folder projects I've created and nothing else. – BryanH Apr 08 '19 at 10:54
  • so from here, run `rm -r .git` to remove the `.git` directory. If you have none here, it means you ran the `git init .` in some parent directory. – padawin Apr 08 '19 at 10:59
  • To be certain, this command `rm -r .git` (instead of `workspace/.git`) will not remove git from all the subfolders, if I understand correctly? – BryanH Apr 08 '19 at 11:29
  • It will remove just the directory you pass in argument (`.git`), not any subdirectories – padawin Apr 08 '19 at 11:43
  • I might add, these folders are all on Cloud9. But I wouldn't think that would affect the use of it's terminal or the commands in Git. – BryanH Apr 08 '19 at 11:47
  • Ok this seems to have worked. I will say it prompted a LOT of lines wanting a 'y' or 'n' response, which was rather intimidating. First line was: `rm: remove write-protected regular file ‘.git/objects/91/`….(then lots of letters & numbers). After typing a 'y' then enter, it prompted another similar line: `rm: remove write-protected regular file ‘.git/objects/fe/`....(then another set of letters and numbers.) I then typed 'n' for this and the next 20 or so similar prompts! Not sure what all that was asking about. – BryanH Apr 09 '19 at 02:53
  • https://linux.die.net/man/1/rm You can use `rm -rf .git` to delete the whole directory without confirmation. You want it all deleted. – padawin Apr 09 '19 at 07:41
0

git init probably did nothing.

I would run a git status to see all of the files you added with your git add -A command and "unadd" the files you no longer want there by running git reset [filename]

Mike Faber
  • 481
  • 5
  • 17