4 ms·
I've heard advice from #git on freenode not to use "git commit --amend", especially on shared repos. I wish I still had a log of the conversation or remembered
by pmoriarty 10y ago
I've heard advice from #git on freenode not to use "git commit --amend", especially on shared repos.
I wish I still had a log of the conversation or remembered the exact problem that led up to it, but it involved a simple amend totally screwing up my repo, and I've avoided it since.
- nchelluri 10y agoI upvoted and am hopefully awaiting a response from someone who can chime in and explain why this is a problem. Amend after push, I could see. You commit, push, amend, push, but after your first push someone else pushes... then you have two heads. I could see that, but I'm guessing you'd mention that if it were the case. If one were to attempt avoiding amend you could always make all changes in a feature branch and rebase this branch onto your target afterwards, squashing commits.
- maw 10y agoIt's much like rebasing, with a similar set of benefits and drawbacks. Once other people can be expected to have done work based on your amended or rebased work, you can expect some annoyances (or worse). If you haven't pushed yet (or if you're really, really sure nobody's basing further work on something you've recently pushed), I say go crazy and amend and rebase to your heart's content.
- eosrei 10y agoThe problem occurs when you amend a commit that someone else is already using. That is rewriting the shared history. A merge commit is required to get the branches in sync again. Amending your commit in your own feature branch or fork isn't a problem. I often amend commits to make a cleaner git history to ease PR/code review. git checkout master git checkout -b 10-new-feature # Make changes git add example.code git commit git push origin 10-new-feature # Oops... left a debug message, fix it. git add example.code git commit --amend git push -f # Rewrites the remote history with your local modified version Consider --amend as the "Just the last commit" form of rebasing.