3 ms·
OK now I know about: "git pull --rebase" If only somebody would explain what this really does! The man pages are not helpful! git-pull(1) Manual Page says: "
by acqq 17y ago
OK now I know about:
"git pull --rebase"
If only somebody would explain what this really does! The man pages are not helpful!
git-pull(1) Manual Page says: "--rebase: Instead of a merge, perform a rebase after fetching. If there is a remote ref for the upstream branch, and this branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes. To make this the default for branch <name>, set configuration branch.<name>.rebase to true."
Oh how clear. So let's try git-rebase:
"If <branch> is specified, git rebase will perform an automatic git checkout <branch> before doing anything else. Otherwise it remains on the current branch.
All changes made by commits in the current branch but that are not in <upstream> are saved to a temporary area. This is the same set of commits that would be shown by git log <upstream>..HEAD (or git log HEAD, if --root is specified).
The current branch is reset to <upstream>, or <newbase> if the --onto option was supplied. This has the exact same effect as git reset --hard <upstream> (or <newbase>). ORIG_HEAD is set to point at the tip of the branch before the reset.
The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order. Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD..<upstream> are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped)."
I'm lost!
Now can anybody explain so nice like Yehuda did about the workflow, what and why that
git pull
did "wrong", and what the hell is that that "--rebase" does "right." Especially as here and there "--rebase" is described as something that "doesn't keep history" and therefore "bad."
Note that I put "bad" "wrong" and "right" in quotes. I know that's all relative, I just want to get some simple explanation what's going on without reading "recursion see recursion" man pages!
Thanks in advance!
- mgrouchy 17y agoI don't think "git pull" does anything particularly incorrect. Its just that when you have merge issues with a git pull you have to resolve all merge issues at the one time(as in resolve all changes all together). Someone can correct me if I am wrong, but a "git pull --rebase" will put all your current local commits aside and then pull everything from wherever you are pulling, applies those changes to the tree without your local changes, then applies all your changes in order one by one, until you are current with both the remote and local changes. If there is a problem with a merge on one of your applied changes, your rebase pauses , you fix the conflict as you would normally and then continue your rebase(as outlined in the article). Essentially the rebase takes all your changes and applies them in order on top of the changes you are pulling. Once again, if I made any mistakes in this explanation, someone please correct me.
- kemiller 17y agoPull with rebase essentially takes all of your local commits and applies each one in turn to the remote head as if each one was a patch. Plain "git pull" doesn't do anything wrong at all, rebase is just a different style. It lets you deal with conflicts one by one, in the context of the original commit. I actually disagree with Yehuda on this one. I like pull-with-rebase in the case where there are no conflicts, but if there are conflicts, I'd rather have a record of the original work, plus a special commit that shows the work done to reconcile in the case of a conflict. But that's really a matter of taste.
- deleted 17y ago[deleted]
- Xurinos 17y agogit pull = git fetch remotebranch + git merge newstuff git pull --rebase = git fetch remotebranch + git rebase newstuff Standard merge feathers commits together. Rebase looks at your new changes, puts them aside, brings in the remotebranch's changes, and then replays all your new changes on top of the remotebranch. This is great because it makes YOUR changes truly new, and you can handle all your conflicts once. http://darwinweb.net/articles/86 http://darwinweb.net/articles/86
- js2 17y ago"git pull" -> git fetch + git merge "git pull --rebase" -> git fetch + git rebase git fetch is what syncs the remote changes to your local repo. . If you want to see these changes, they are referenced by so-called remote-tracking branches. To view them use: git branch -r Now, if your local branch (let's say its master) has not diverged from the remote branch to which it corresponds (typically origin/master), then it doesn't matter whether you use rebase or merge. In the case where your local master is a superset of the remote master, there are no new remote changes to incorporate. In the case where where your local master is a strict subset of the remote master, then either rebase or merge will perform a so-called "fast-forward" operation which basically just updates your local master to the same commit as the remote master. However, if your local master has diverged from the remote master, then there is work to do: Rebase will take all your new local commits, set them aside, reset your local master to the same commit as the remote master, then replay your commits one at a time. If there are conflicts, you will of course have to resolve them as you go. Merge, on the other hand, will attempt to create a merge commit. A merge commit is one that has two parents. In this case, the parents are the tip of the remote master and the tip of the local master. Of course, here too there may be conflicts for you to resolve. Regardless of whether you performed rebase or merge, when done, your local master is now a superset of the remote master and you can push out the change. (Unless of course, while you were rebasing/merging, someone else pushed their changes. In this case, wash, rinse, repeat…). Now, as to whether to use merge or rebase… there is no right answer. It very much depends on the workflow. Rebase will give you a "cleaner" history in the sense that the history remains linear which some folks prefer. A linear history is easier to understand and if you ever need to use "git bisect" to find where something broke, a linear history is much easier to deal with. However, some folks prefer to see the true history of development in the sense of "when so-and-so started this work, on which commit was it originally based?". In that case, merge preserves that information (as long as it wasn't a fast-forward -- but you can always force a merge commit with "git merge --no-ff"). In some cases, it makes sense to use both rebase and merge -- rebase for simpler changes and merge to incorporate long-lived topic-branches. It pains me that the git man pages are so awful. Patches welcome (it is unfortunate that newbies provide the best perspective on how awful the docs are, while simultaneously are the least likely to be able to contribute improvements to them). Ultimately, git is actually based on some fairly simple concepts and I happen to think that once you have a conceptual understanding of it, all the commands (more or less…) start to make sense. So I strongly advocate trying to understand what the heck is going on under the hood. That said, the Pro Git book is a much better place to start learning git than the git man pages. Hope this helps.