4 ms·
This might be obvious, but it's worth checking out git commit --amend. Then you can be regularly committing, but to the same commit.
by robertlagrant 4y ago
This might be obvious, but it's worth checking out git commit --amend. Then you can be regularly committing, but to the same commit.
- shagie 4y ago--amend would interact with the remote system poorly if there's a push with each commit.
- sjburt 4y agoYou have to force push, but you have to do that when pushing a rebased branch as well. In either case it’s a history rewrite. It’s not a big deal unless other people have pulled that branch—if they have they will need to reconcile things on their end as well.
- dnsmichi 4y agoDepending on the workflow and collaboration in branches in teams, amending may not be ideal. Amending changes to an existing commit will generate a new sha checksum, thus resulting in a diverging history if the branch is often pushed to the remote Git server. That's one of the rare cases where "git push --force" makes sense but also requires awareness for other collaborators on the branch - they need to run "git fetch && git reset --hard origin/branchname" every time, and best "git stash" to temporarily remove any local changes, with running "git stash pop" afterwards. One reason to regularly push commits can be to trigger CI/CD, security scanning and dev/staging deployments or review apps. GitLab team member here - before joining GitLab in 2020, I was a Git/GitLab trainer. https://www.netways.de/en/blog/2018/05/24/releasing-our-git-and-gitlab-training-as-open-source/ https://www.netways.de/en/blog/2018/05/24/releasing-our-git-...
- tspike 4y agoI've completely replaced my use of --force with --force-with-lease. It does the same thing, except it will abort if the upstream branch has been updated since your last pull. This pretty much prevents the concerns about clobbering others' work.
- dnsmichi 4y agoAfter reading this comment about "git push --force-with-lease" in https://stackoverflow.com/a/53011907/1821348 https://stackoverflow.com/a/53011907/1821348 my workflows with "git fetch" first would not work with "git push --force-with-lease", behaving as if "git push --force" was run. Theoretically - I need to do some testing here. Thanks for the pointer into learning something new :)
- robertlagrant 4y agoFor sure, it doesn't work with every workflow. But I think it would for the OP's described workflow. And I am currently waiting for my GitLab backpack for contributing something (very small, but apparently it counted!) so thank you to the team for that!
- dnsmichi 4y agoThanks for sharing your ideas, appreciate the thoughts to learn new perspectives :-) And also thanks for contributing, every contribution counts and helps :-) Maybe see you at a future hackathon :) https://about.gitlab.com/community/contribute/ https://about.gitlab.com/community/contribute/
- usr1106 4y ago--amend if you have a modification to your most recent commit. --fixup if you have a modification to an earlier commits rebase --autosquash amend the fixup(s) to the commit(s) they belong too. (Of course you need to know what you doing. Otherwise you create conficts tedious to resolve in the rebase)