What exactly should I do in order to
git checkout -b new_one; git cherry-pick commit_id
, am I right?) new_one
to master
? Of course, any change should be also pushed to remote.
Thanks.
In order to obtain a fresh master that only holds one commit, the easiest is to create a fresh repo and then put the current state of master
into it as initial state. Otherwise, you'll always have the history of master
present:
git archive --format zip --output /full/path/to/zipfile.zip master
git init .
git add . && git commit -m "initial"
remote
: git remote add ...
master
there: git push -f origin master:master
Then, your repo will have only one branch ( master
) with only one commit.
Create new_branch
starting it off commit_id
:
git branch new_branch commit_id
Check out to it:
git checkout new_branch
Delete old master
branch:
git branch -d master # you may need to use -D, with history loss may occur
Rename new_branch
to master
:
git branch -m new_branch master
Note that this does not necessarily remove all history - even if you perform full garbage collection, any objects that commit_id
was referring to will remain in git history (and git object store).
I would try something like this:
git branch tmp <the very first commit in the repo>
git checkout tmp
git merge --squash <commit_id>
git branch -d master
git branch -m tmp master
... followed by a forced push
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.