Git remove commit history but ke
2019-08-16 本文已影响0人
JaedenKil
Say I start a project, and make a lot of commits now and then, finally the project is OK to init, but the commit history is unnecessary.
GitDemo (master)
$ git log --oneline
51fd1e8 (HEAD -> master) Add file03
0c4bbec Add file02
8e4c178 Add file01
---------------------------------------
GitDemo (master)
$ git checkout --orphan dev
Switched to a new branch 'dev'
---------------------------------------
GitDemo (dev)
$ git reflog
fatal: your current branch 'dev' does not have any commits yet
----------------------------------------
GitDemo (dev)
$ ls -al
total 40
drwxr-xr-x 1 zzheng 1049089 0 Aug 16 16:51 ./
drwxr-xr-x 1 zzheng 1049089 0 Jul 24 18:04 ../
drwxr-xr-x 1 zzheng 1049089 0 Aug 16 16:57 .git/
-rw-r--r-- 1 zzheng 1049089 0 Aug 16 16:50 file01
-rw-r--r-- 1 zzheng 1049089 0 Aug 16 16:51 file02
--------------------------------------------
GitDemo (dev)
$ git status
On branch dev
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file01
new file: file02
new file: file03
----------------------------------------------
GitDemo (dev)
$ git commit -m "Init project"
[dev (root-commit) 924b8e0] Init project
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file01
create mode 100644 file02
create mode 100644 file03
-----------------------------------------------
GitDemo (dev)
$ git branch -m master
------------------------------------------------
git push -f origin master