3 ms·
Git tries pretty hard to avoid this now; it won't treat fast-forwards as merge commits, it will just fast-forward you. Apparently this was not always the case.
by jrockway 17y ago
Git tries pretty hard to avoid this now; it won't treat fast-forwards as merge commits, it will just fast-forward you. Apparently this was not always the case.
Anyway, "git pull --rebase" is your friend. (And so is "git push --force". git pull will DTRT on the other end, so this shouldn't mess anyone else up.)
- tlrobinson 17y agoAnd so is "git push --force". Wait, what? I thought you were supposed to avoid "push --force" when pushing to a public repo?
- jrockway 17y agoIt doesn't break git, but it may confuse your contributors.
- pyre 17y agoI'm thinking that he means, if everyone is doing git pull --rebase then a git push --force won't screwup the people you are sharing with. My manpages still seem to warn against using both commands, but I'm locally running on a version dated 2/09/2009 (I have a cronjob at work that pulls down the latest version of git and compiles it daily). [edit] Maybe by 'do the right thing' he means that it won't overwrite their local history (i.e. the pull/merge will fail because the histories are different)
- jrockway 17y agoAll I know is that I "git push --force" all the time, and it has never caused anyone tracking my repositories to complain or stop sending me patches. I assume this means git handles it fine. (I just tested this, and git does handle it fine. It says "forced update", and everything works normally. The reflog stores the old pre-force-push tree still, so you are free to revert and push -f the "old" tree, if you really feel the need to.) Anyway, "git push --force" has the potential to lose data, but less potential than "rm -rf .". You will destroy your central repository, not anyone's actual work. ("Destroy your central repository" sounds bad, but isn't. The important copy is the one on your disk.) A clean history is better than never using "push -f" IMHO. The manual authors apparently disagree.
- pyre 17y ago> The manual authors apparently disagree. Pushing doesn't always mean to a central repository. Since there is no distinction, you could be git pushing while on a branch that is tracking a topic branch in someone else's local (local to them) repo.
- jrockway 17y agoPushing to non-bare repositories is always considered harmful.
- cookiecaper 17y agoTotally with you on git pull --rebase. Thing is great. More skeptical on git push --force, I think it's better to just revert/make new commits to fix your screwups.
- schacon 17y agoplease don't "git push --force" unless you know what it's doing, people - you will lose work and people will get really confused. the --force should never be necessary, even when using 'pull --rebase'. the push command normally will refuse to push unless the latest commit on the server is in your history somewhere. this means that if someone pushes since you last pushed or fetched, introducing commits you have not seen yet, and you try to push, it will not let you until you have pulled them down and either rebased your local work on top of it or merged your work with it. '--force' overrides this check, pushing anyways, effectively losing (possibly multiple) commits on the server. it should only be used if you were forced to change your history somehow (removing files with a password in it, rewinding work in an emergency), it should almost never be used and there should be a really good reason for it. i've used it maybe a dozen times last year of the thousands of pushes i've done.
- jrockway 17y agoI liberally rewrite my history; this is why I push --force. I don't view version control as an auditing tool, I view it as a debugging tool. YMMV.
- schacon 17y agoif you are the _only_ person with push access to your repo, then that's fine. i just don't want other people reading this that collaborate with people on repos that multiple devs have push access to thinking that --force is fine to use, because it will lose commit data.