3 ms·
> It would have been easier to copy all the source files out, check out the branch I wanted, then copy them all back in. That would be "git checkout -b some-b
by Shacklz 4y ago
> It would have been easier to copy all the source files out, check out the branch I wanted, then copy them all back in.
That would be "git checkout -b some-branch" and then "git reset --soft origin/main" (or whatever branch you want to be on top of).
"reset" sets the pointer where you want it to be, "--soft" ensures that the actual files on your filesystem (the working tree) isn't touched. You will then have uncommitted files (your changes compared to the origin/main), that you can then recommit everything the way you want it.
reset --soft is my goto-recommendation for devs who have to satisfy a linear history but don't really care about git-history at all. Just do your changes as you normally would, using merge and whatever else floats your boat, and then once you're done, just use a soft-reset and then commit everything in one single commit. It's of course not ideal (meaningful atomic commits or some such would be better), but compared to having dozens of "fix stuff" and "merge from main" commits, it's definitely better.