Есть ли команда отменить git init?
Я просто Git init’ed репозиции с неправильным пользователем и хочу его отменить. Есть ли какая-нибудь команда для этого? Нужно ли мне входить и редактировать каталог .git?
5 ответов
Если вы просто ввели его, вы можете просто удалить .git. Как правило:
Затем заново создайте в качестве правильного пользователя.
В окнах введите rmdir .git или rmdir /s .git , если папка .git имеет подпапки.
Если ваша оболочка git не настроена с правильными правами администратора (т.е. она отказывает вам при попытке rmdir ), вы можете открыть командную строку (возможно, как администратор — нажать клавишу Windows, cmd ‘, щелкните правой кнопкой мыши «командную строку» и выберите «запустить как администратор» и попробуйте те же команды.
Git хранит все свои файлы в каталоге .git. Просто удалите этот и снова запустите.
Этот пост хорошо показывает вам, как найти скрытый файл .git в Windows, Mac OSX, Ubuntu
удалите папку .git в корневой папке проекта
если вы установили подмодули и хотите удалить их git, также удалите .git из папок подмодулей
Я запускаю Windows 7 с консолью git bash. Вышеуказанные команды не будут работать для меня.
Итак, я сделал это через проводник Windows. Я проверил показ скрытых файлов, перешел в каталог проектов и вручную удалил папку .git. Затем вернитесь в командную строку, которую я проверил, выполнив git статус.
fatal: не репозиторий git (или любой из родительских каталогов):.git
Это именно то, что я хотел. Он вернул, что каталог не репозиторий git (больше!).
How to Delete Git Repository Created with Init
To undo the changes made by git init you should delete the git repository. Follow the steps below to make the job done.
- Open the Terminal by typing the Ctrl + Alt + T
- Next type the following command line which will delete the git repository and undo the changes made by git init :
Solution for Windows
The method to undo the changes for Window differs from other operating systems. Here are the steps to follow.
- Open the Run prompt by pressing Windows + R .
- Then, type cmd and press Shift + Ctrl + Enter to provide administrative privileges.
- Run the following to delete the repository and press Enter :
If the repository has subfolders, then execute:
Solution for Mac OS
In this section, we will demonstrate to you two ways of detecting the hidden files and deleting them in Mac OS.
-
In the framework of the first method, first, you should open the terminal and run the code below:
Then, you should type cmd + SHIFT + . to display hidden files in Finder.
Then, you should also type cd , drop your git repository folder from Finder to the Terminal window, and press return .
And, finally, you can delete them by just moving them to trash.
The git init Command
The git init command generates a new, empty git repository or reinitializes an existing one. A repository is a storage of the project files, which makes it possible to save code versions and have access to them. This command creates a .git subdirectory which includes the metadata, like subdirectories for objects and template files to generate a new repository.
Undo Git Init: A Guide
This guide discusses why you may want to undo the git init command and the effects of doing so. We’ll walk through an example of undoing git init so you can learn how to perform this task on your own.
Git Init: A Refresher
To initialize a Git repository , we must use the git init command. This command creates all of the configuration files and folders necessary to work with the Git version control system in a given folder.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
Select your interest
First name
Last name
Phone number
By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.
You only need to run the git init command if you are creating a repository from scratch. Cloned repositories are accompanied with all the configuration information you need.
When you run git init, a folder called .git/ is created. Within this folder, you will find a list of files that relate to the branches of a repository, what HEAD you are viewing, and other crucial pieces of information about Git.
The .git/ folder is hidden. This is because the folder begins with .git/. This folder is hidden to protect you from accidentally deleting its contents.
If we use the ls command , we can see this folder:
The -la flag lets us see all the files in a folder, including hidden files:
This is what a basic repository would look like after it has been initialized. We have a folder called .git/ with our configuration. README.md is the only file in our repository.
Undo Git Init
The Git command line does not give us a “git init undo” command. This is because undoing a git init operation is as simple as removing the .git/ folder.
We can remove this folder using the rm -rf command :
This command does not need sudo privileges because the .git/ folder should share the same privileges as all the files and folders in your repository.
«Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!»
Venus, Software Engineer at Rockbot
Find Your Bootcamp Match
On Windows machines, you can delete the .git/ folder using the following Git shell command:
This command removes the folder .git and all of the subdirectories the folder contains.
Do You Need to Undo Git Init?
Before you remove the .git folder from a project, ask yourself whether you need to delete the folder.
A common reason why you may want to delete the .git/ folder is that you have initialized a repository in the wrong directory and need to start over.
Deleting the .git/ folder comes with serious ramifications. If you have not created any commits in a project, deleting the folder will only cause you to lose a few configuration files. If you have created commits and you have not pushed them to a remote repository, you will lose the entire history of your project that was stored in git.
Only consider deleting the .git/ folder as a last resort if you encounter an issue with a configuration file that you cannot resolve. Always check for a better method of solving any issue you encounter with Git.
As a final warning, there is no going back after you delete the .git/ folder.
Conclusion
While there is no undo git init command, you can undo its effects by removing the .git/ folder from a project. You should only do this if you are confident in erasing the history of your repository that you have on your local machine.
Now you have the knowledge you need to undo a git init operation like an expert!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.
Как отменить команду 'init' в Git?
Git — это система, которая используется для отслеживания изменений в исходном коде во время разработки приложения. Это форма контроля версий, в которой кодовая база для приложения отражается на компьютере каждого разработчика. Это позволяет разработчикам координировать работу между собой и улучшает целостность кода, предоставляя возможность отслеживать все изменения, внесенные в код.
Команда git выполняется
Команда « git init » чаще всего является первой командой, которую запускает пользователь при запуске нового проекта. Эта команда позволяет пользователю создать новый репозиторий Git. Команду можно использовать для преобразования старого проекта в репозиторий Git или для создания нового репозитория. На этом шаге мы научим вас, как отменить эту команду и отменить изменения, внесенные этой командой.
Как отменить команду «init» в Git?
Чтобы отменить действие команд «init» на компьютере, мы выполним команду для удаления только что созданного репозитория git. Убедитесь, что вы точно выполнили команду, следуя указанному методу. Метод немного отличается для Windows и Linux.
Способ 1: для Linux
На этом шаге мы будем отменять изменения, внесенные командой «init», удалив репозиторий git. Для этого мы будем выполнять команду в терминале. Для этого:
-
Нажмите « Ctrl » + « Alt » + « T », чтобы открыть терминал.
Способ 2: для Windows
Способ отмены изменений, внесенных командой init для Windows, немного отличается от Linux. В Windows есть другая команда, которая может быть выполнена в командной строке для отмены изменений. Поэтому на этом этапе мы будем запускать командную строку от имени администратора и выполнять команду. Для этого:
- Нажмите « Windows » + « R », чтобы открыть окно «Выполнить».
- Введите « cmd » и нажмите « Shift » + « Ctrl » + « Enter », чтобы предоставить административные привилегии.