0

I want to upload the project to remote but I can't with the first few commits.

For example I have git commits like this:

...(Many new commits)

  • Presentable Commit
  • Commit I don't want to share #4
  • Commit I don't want to share #3
  • Commit I don't want to share #2
  • Commit I don't want to share #2
  • Commit I don't want to share #1

I looked through sources that suggested using git rebase -i, I expected it to just remove the commits which I squashed but that seems to cause merge conflicts even though I am not changing anything at all. How can I just cut off the tail as if I didn't make those 4 commits?

2

1 Answer 1

2

If it is a straight line history, you can do this:

git branch --orphan new-branch commit5 # create a new branch that starts with the content of commit 5, no history
git commit -m "Starting the history of the project _again_"
git cherry-pick commit5..original-branch

That will create a history like the one you want.... if you like it, feel free to place whatever branch you like there and delete new-branch

git checkout -B main # set main over here. If it exists already, move over here
git branch -d new-branch # delete new-branch

If is is not a straight line history (you have merges and stuff), you can use a script I have developed for this (https://github.com/eantoranz/git-replay):

git branch --orphan new-branch commit5 # create a new branch that starts with the content of commit 5, no history
git commit -m "Starting the history of the project _again_"
./git-replay.py HEAD commit5 the-original-branch

That will print the ID of a commit that has a history like the one you want. Take a look with git log or do a checkout on it.... if you like it, then place a branch on the commit and remove new-branch as there is no need for it anymore.

Not the answer you're looking for? Browse other questions tagged or ask your own question.