1

At the beginning I committed a few test commits with 600k+ rows of Code. After that I deleted all files and just used git like normal.

Now I see in the contributors statistic that I added and deleted over 650k+ rows of Code.

Is there a way to delete the first test commits? (I just want to get the statistic right)

Edit: that's my commit history:

  • 1 Commit: +600k rows (Initial commit)
  • 2 Commit: -600k rows (master is now empty)
  • 3 Commit: +100 rows (just gitignore) <-- I would like to have this as initial commit
  • 4 Commit: +30k rows (my normal work) ...
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sirzento
  • 537
  • 1
  • 5
  • 23
  • You can, but I don think that it will hurt the spirit of git, namely keeping track of history. – YesThatIsMyName May 15 '19 at 13:20
  • you can do git squash – Alexan May 15 '19 at 13:21
  • @Alexan Isn't git squash only applicable only for the last n commits? – YesThatIsMyName May 15 '19 at 13:23
  • @YesThatIsMyName I know but I did the first commits just to test if I can commit somehting. It doesnt even have to do with the current work (Ist my first time with git, thats why I tested it) – sirzento May 15 '19 at 13:23
  • @sirzento I think the only way is to use a clean branch and manually fix the first commits ... then merge the ones afterwards from the current branch. – YesThatIsMyName May 15 '19 at 13:25
  • 1
    https://stackoverflow.com/questions/435646/combine-the-first-two-commits-of-a-git-repository – Alexan May 15 '19 at 13:29
  • would this remove the 600k+ rows from the contributors statistic but Keep my statistic after that? – sirzento May 15 '19 at 13:33
  • Maybe you want just this? https://stackoverflow.com/questions/750172/how-to-change-the-author-and-committer-name-and-e-mail-of-multiple-commits-in-gi – YesThatIsMyName May 15 '19 at 13:34
  • 1
    @YesThatIsMyName you mean I change the test commits to another user so my statistics are fine and just have a 'testuser' with the commits? – sirzento May 15 '19 at 13:37
  • Actually, @Alexan 's suggestion will let you remove any commit, including the initial one. This will truly delete their data (well, almost: at least if you `push` them, the server won't have these data). – Ruslan May 15 '19 at 13:37
  • @Ruslan Isnt this link to a question how to combine commits and not how to delete? – sirzento May 15 '19 at 13:40
  • `git rebase -i` can do all these things: edit, squash, remove... Just try it: the comments in the config file which will open are pretty well written. – Ruslan May 15 '19 at 13:43

1 Answers1

1

Suppose the branch is called master and it has 10 linear revisions.

git checkout master~7 # checkout the 3rd revision from history
git reset --soft master~9 # set branch pointer at first revision, all diffs between master~7 and master~9 are on index
git commit --amend --no-edit # now first revision has the content (working tree) of master~7, so first two revisions from master are gone
git cherry-pick master~7..master # replay history
# if you like the result
git branch -f master # set master on new branch
git checkout master
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • So with say 30 Revision and want to have the 4th commit as start it would be: checkout master~26, --soft master~29 and cherry-pick master~26 ? – sirzento May 15 '19 at 13:55
  • One last question. i have a merge of 1 file. the merge was with '17a9c4b' + '1e43056' into commit '47f92b3'. Would be `git cherry-pick master~26..master -m 1 47f92b3` correct if the change from 1e43056 can be dropped and use the first parent? – sirzento May 15 '19 at 14:16
  • I guess you could use the options for cherry-pick that keep merges in history. – eftshift0 May 15 '19 at 14:26