0

I developed locally and now wanted to release a project on Github.

The challenge is: I don’t want to push all the chaotic and messy history from day 1, but want to start with a certain commit, or maybe tag, to be my first released commit on the remote GitHub repo.

How can one achive this?

All the googling and stackoverflowing only brought instructions for how to push UP TO a certain commit (git push origin $commit:$branch), but not STARTING FROM a certain commit. I also tried rebase, but this doesn’t seem to do the trick.

I’d like to do this with Git Extensions GUI on Windows, but would also use the command line in Git Bash, if I have to.

Hoping for help and thanking you very much! DW

Darkwing
  • 140
  • 1
  • 5
  • 2
    You can create an orphan branch. But you cannot start from 100th commit, because you have to push diffs. The 100th commit holds a diff (difference) with 99th. But you don't want to push 99th. Then what will a branch hold? Like in a tree, you cannot hang a part of a branch with leafs in an air, it grows from a root. – CoolMind Nov 03 '21 at 18:14
  • 1
    @CoolMind "*…you have to push diffs. The 100th commit holds a diff (difference) with 99th.*" No. Every commit stores the entire snapshot of the working tree. Git is snapshot-based, not diff-based. – phd Nov 03 '21 at 19:45
  • 2
    You could squash the chaotic and messy history into a single nice commit. – matt Nov 03 '21 at 23:34
  • 2
    See [here](https://stackoverflow.com/q/19641108/1290731) for a general way to do it. – jthill Nov 04 '21 at 00:31
  • @phd, SVN holds files, while Git holds diffs. You can see it in commits (they show only changed strings in files). That's why Git repository is light-weight. If you add a movie file, it will add many megabytes one time, not every. – CoolMind Nov 04 '21 at 19:23
  • @CoolMind "*…Git holds diffs.*" No, Git stores the entire copies of the worktree. "*You can see it in commits (they show only changed strings in files).*" That because `git diff`, `git log`, `git show` **calculate** those diff. Git doesn't store diffs but calculates them. "*That's why Git repository is light-weight."* No, the real reason is that Git eliminates duplicates. Though Git stores multiple copies of the worktree it never stores the same unchanged file twice — the second time it stores a lightweight link into the previous snapshot. Please learn Git internals before making wrong claims. – phd Nov 04 '21 at 20:03
  • 1
    @CoolMind https://stackoverflow.com/q/8198105/7976758 ; https://stackoverflow.com/search?q=%5Bgit%5D+How+does+git+store+files – phd Nov 04 '21 at 20:08

1 Answers1

1

A commit is a complete state of your project. So it sounds like your "certain commit" is the first state of your project that you want to expose to the public. Thus it makes no difference how the history that led up to that state is expressed; a state is a state.

So the simplest approach is just to squash all of the commits after the initial commit (which is probably empty) up to and including the "certain commit" into a single commit. This will look exactly the same as it looks now, but historically it will appear to spring full-grown from the initial empty state.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks! Git squash should be the command that should help me ... but exactly that one little constrain of your solution makes it not work for me: I did not start with an empty repo. That means I can not squash an commit from zero to public release. – Darkwing Nov 04 '21 at 12:09
  • I believe I should accept jthill’s comment above as an answer; he pointed to [Split git repo in a squashed public and initial private](https://stackoverflow.com/questions/19641108/split-git-repo-in-a-squashed-public-and-initial-private). That would achieve the outcome I desire – but actually the method is too much hassle for me atm. – Darkwing Nov 04 '21 at 12:15