Home git How to undo git init in an existing repository?

How to undo git init in an existing repository?

Author

Date

Category

In the folder with git-th accidentally clicked on the git init , the result is now when I do git status I have all the files are displayed as changed.

The git log last commit remained. How to undo the command git init ?


Answer 1, Authority 100%

If you just happened to have created a repository, you need to delete the folder .git in the root. It will completely destroy the repository and, of course, cancel that made git init . After a * nix-console is done so:

rm -r .git

If you have done git init in an existing repository, be afraid nothing :

Running git init in an existing repository is safe . It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates (or to move the repository to another place if –separate-git-dir is given).


Answer 2, authority 42%

According to the description, the command git init was carried out not in the root directory of the project, and in a nested. In this case, all that is within this nested directories inside it is considered a new repository (and outside – old)

.

When you perform any Git commands in a directory there is a recursive search of the repository from the bottom up. Those. check the current directory, then its parent, then the parent’s parent, etc. Once the directory is .git , a further search is terminated.

Suppose we have such a structure. In the root directory of the project A is initialized repository Git.

A
| -.git
| -A / B
| -A / C
  | -A / C / X
  | -A / C / Y
  | -A / C / Z
| -A / D

Now we initialize the new repository in the directory A / C :

$ cd C
$ Git init
A.
| -.git
| -A / B
| -A / C
  | -.git
  | -A / C / X
  | -A / C / Y
  | -A / C / Z
| -A / D

Now the situation is as follows:

When performing any Git command from the directory A , A / B , A / D , detected repository in the directory A .

When performing any command from the directory Git A / C and nested repository found in the directory C . Since he had just created, all files are displayed as new.

To fix the situation, it is sufficient to remove the .git from the directory A / C :

$ rm -rf A / C / .git

Answer 3, authority 16%

If you do not bare -repozitory, it consists of a repository that is stored in the directory .git , and the so-called working tree , ie, files and directories, change history, and that you are tracking with the help of git .

directory (or file) .git , if not used, for example, sub-modules (submodules), there should be only one.

look into the depths of working tree Other directory .git .

If you find a (-ie) catalog (s), try to move (without removing) it (them) in any other place outside the working tree and check if everything is in order with git log and git status .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions