How to rebase all the commits from the beginning

后端 未结 5 714
北荒
北荒 2021-01-31 07:12

So I\'m migrating from svn (code.google.com) to git(github).

I\'ve imported my project from the svn repo, and it imported all the commit history along way. I\'m not real

相关标签:
5条回答
  • 2021-01-31 07:47

    Find the hash of the commit that you want to start squashing from say abcd12 and then rebase against that hash specifically.

    git rebase -i abcd12
    

    You are using master to rebase against, which performs the rebase against the tip of the master branch.

    0 讨论(0)
  • 2021-01-31 07:48

    git rebase -i --root will start an interactive rebase of all commits from the beginning.

    From there, you can squash all commits into one and/or perform other edits.

    0 讨论(0)
  • 2021-01-31 07:52

    Jefromi's answer will work, but if you want to keep your existing repo configuration, or even leave around the commits just in case, you could do the following:

    git checkout master

    git branch backup optionally leave another branch here in case you want to keep your history.

    git reset --soft $SHA_OF_INIT_COMMIT this will update what HEAD is pointing to but leave your index and working directory in their current state. You can get the SHA with git log --pretty=format:%h --reverse | head -n 1, and make this one step with git reset --soft $(git log --pretty=format:%h --reverse | head -n 1)

    git commit --amend change your initial commit to point to the current state of your repo.

    0 讨论(0)
  • 2021-01-31 07:55

    You could rebase and squash everything if you wanted to (except the initial commit) but why bother? Simply delete your .git directory, run git init to recreate it, git add everything, and git commit to make a new initial commit.

    0 讨论(0)
  • 2021-01-31 07:56

    If you'd like to reduce all your history to a single "Initial import" commit, simply remove .git directory and create a new local repository (keeping a backup of the old one). git init . && git add . && git commit -m "Initial import".

    Such new repository won't have a common ancestor with the one you've pushed to GitHub, so you'll have to git push --force your newly created repository.

    0 讨论(0)
提交回复
热议问题