30
lxmcf
5y

After using git for all this time... I still can never commit changes correctly .-.

Comments
  • 6
    Isn't this what amend is for?
  • 4
    git commit --amend "let's just replace that last one"
  • 3
    @ilikeglue @C0D4 yes... That would be the case if I hadn't already pushed the changes
  • 5
    @lxmcf do it anyway, and push.

    It will create a merge on the same branch and fix its self.
  • 2
    @C0D4 ... I love you both... Equally
  • 3
  • 3
    Or better yet,
    git rebase -i HEAD~<number of commits>

    This gives you lot's of control over the commit history, but you can edit every commit message in that upstream branch.

    Then, do a git push --force
  • 0
    just rebase the shit and combine the commits you want into one and force push.
  • 2
    git stash
    git rebase -i
    git stash pop

    Commit messages should also be starting with a verb and be in present tense. Doesn't really matter but I think it looks a bit nicer
  • 0
    @sudocode I did that so many times once lol
  • 1
    @C0D4 is there a reason that I should prefer to do a merge? I'm always just "git push --force"ing my amended commits effectively overriding / the placing the old one entirely to keep my commit history as clean and short as possible. Is this considered bad practice?
  • 0
    @ElCapitan question was not for me, but no. Force pushing is not necessarily a bad practice, it's more of a safeguard against accidentally fucking up the repo for everyone else...
    But that what git reflog is for ❤️
  • 0
    @ElCapitan Well you should never force push. If you have already pushed then do another commit, else edit your local commits via rebase -i before pushing
  • 0
    @12bitfloat if you never force push, you can't rebase your branch against master.
    This leaves you with merge commits, a dirty and confusing history and the dissaproval of your peers.
  • 0
    @Cybork You can rebase locally before pushing. If you have already pushed you might force push to clean it up but only if you know exactly what you're doing and nobody else is working on the branch
  • 0
    @12bitfloat I push alot, the fear of an HD frying mid-work is real !
    But yes, rule #1 of force pushing is know what you're doing, rule #2 is pulling main branch before
  • 0
    @Cybork "nobody else is working on the branch" is the most important thing when force pushing. Pulling doesn't really matter if someone else has already cloned. That's how you corrupt the repo
  • 2
    If you have to force push, you are doing it wrong, why give yourself the headache of having to rebase the branch just because you don't give a shit about other people's work.

    Now if it's a solo repo and your the only dev, do as you please - its only your code. If it's a team based repo it will eventually become a problem that will need to be corrected.

    As for commit history beiNg messy, this is a pro and con of transparency.
  • 0
    @C0D4 I agree: If your pushes are ugly, don't push ugly commits
Add Comment