markdown Git删除我们的所有提交历史记录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Git删除我们的所有提交历史记录相关的知识,希望对你有一定的参考价值。

### First Method

Deleting the `.git` folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

```
# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

# Delete the old branch:
git branch -D master

# Rename the temporary branch to master:
git branch -m master

# Finally, force update to our repository:
git push -f origin master
```

This will not keep our old commits history around. **But if this doesn't work, try the next method below.**

### Second Method

```
# Clone the project, e.g. `myproject` is my project repository:
git clone https://github/heiswayi/myproject.git

# Since all of the commits history are in the `.git` folder, we have to remove it:
cd myproject

# And delete the `.git` folder:
git rm -rf .git

# Now, re-initialize the repository:
git init
git remote add origin https://github.com/heiswayi/myproject.git
git remote -v

# Add all the files and commit the changes:
git add --all
git commit -am "Initial commit"

# Force push update to the master branch of our project repository:
git push -f origin master
```
**NOTE:** You might need to provide the credentials for your GitHub account.

copy from: https://gist.github.com/heiswayi/350e2afda8cece810c0f6116dadbe651

以上是关于markdown Git删除我们的所有提交历史记录的主要内容,如果未能解决你的问题,请参考以下文章

git删除所有提交历史记录

git删除所有历史提交记录

git删除所有历史提交记录,只留下最新的干净代码

如何从 Git 历史记录中永久删除提交?

从远程 git 历史记录中删除我在本地没有的提交

git删除所有提交历史记录