Перейти к содержимому

Как удалить git init

  • автор:

Как отменить git init в уже существующем репозитории?

В папке с git-ом случайно нажал на git init , в итоге теперь когда делаю git status у меня все файлы отображаются как измененные.

В git log последние коммиты остались. Как отменить действие команды git init ?

MSDN.WhiteKnight's user avatar

Если просто случайно создали репозиторий, то нужно удалить папку .git в корне. Это полностью уничтожит репозиторий и, разумеется, отменит то, что сделал git init . Через *nix-консоль это делается так:

Если же Вы сделали git init в уже существующем репозитории, то бояться нечего:

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).

Nick Volynkin's user avatar

Судя по описанию, команда git init была выполнена не в корневой директории проекта, а в одной из вложенных. В таком случае всё, что внутри этой вложенной директории, изнутри нее считается новым репозиторием (а снаружи — старым).

При выполнении любой команды Git в некоторой директории происходит рекурсивный поиск репозитория снизу вверх. Т.е. проверяется текущая директория, потом ее родитель, потом родитель родителя и т.д. Как только находится директория .git , дальнейший поиск прекращается.

Предположим, у нас есть такая структура. В корневой директории проекта A инициализирован репозиторий Git.

Теперь мы инициализируем новый репозиторий в директории A/C :

Теперь наблюдаем следующую картину:

При выполнении любой команды Git из директорий A , A/B , A/D , обнаруживается репозиторий в директории A .

При выполнении любой команды Git из директории A/C и вложенных, обнаруживается репозиторий в директории С . Поскольку он только что создан, все файлы отображаются как новые.

Remove Git Init

Remove Git Init

In this tutorial, we will learn about undoing the effect of the git init command in Git.

The git init command creates a new empty Git repository.

Please enable JavaScript

When used with an existing project directory that is not yet versioned, the git init command transforms the current directory into a Git repository.

Sometimes, we may wish to remove the project directory from the Git versioning system.

We will now illustrate this with an example.

Undoing git init for a Directory in Git

When setting up a repository in Git, we use the git init command.

The git init command creates a directory called .git (a hidden directory) in the project directory. This directory is used to store all the objects and refs that Git uses. These objects and refs created and stored in the .git folder are used by Git for the history of the project directory.

The existence of the .git directory is one that separates a normal directory from a Git repository.

We can see in the following the typical contents of a .git folder of a Git repository.

As mentioned earlier, the git init command creates the .git directory and its sub-directories. These sub-directories are the metadata of the repository.

The HEAD file is created by the git init command, which points to the currently checked-out commit.

Thus, to undo the effect of the git init command means to remove the project directory from the versioning system of the Git; basically, the project directory will no longer remain a Git repository.

To achieve this, we need to delete the .git folder from the project directory.

After deleting the .git folder, the project folder is no longer tracked by the Git versioning system.

Whatever changes done so far will remain, and nothing will be affected.

Of course, as the project directory is no longer a Git repository, we now cannot fetch the new changes pushed into the remote repository.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *