![]() ![]() Considering Git commits are immutable, there’s no way for Git to get the commits from feature into master without changing their parent references.Sublime Merge vs SourceTree (Git client comparison) If you were to merge or rebase the feature onto master, Git would be unable to do a fast-forward because the trees have both diverged. Your repository history would now look like this:įast-forwards don’t happen when changes have been made in the original branch and the new branch. No changes are made to the repository itself, as the commits from the feature already contain all the necessary changes. It simply updates the master branch to reference the exact commit that feature does. It’s now relatively easy to see what’ll happen when Git does a fast-forward. ![]() The feature branch can now be considered ahead of the master. The master branch is still referencing 7ddac6c, while the feature has advanced by two commits. They’ve both got precisely the same history. You’ve got both branches referencing the same commit. This came about because I made dozens of edits but wanted varied branch names to help group the changes.Ī fast-forward is what Git does when you merge or rebase against a branch simply ahead of the one you have checked-out. Instead of git commit -am I am selecting files from the "modified" list produced via git status and then pasting those in this script. Having used this process 10+ times in a day, I have taken to writing batch scripts to execute the commands, so I made an almost-proper git_update.sh script for doing the above steps. $ git commit -m "Webgility ecc desktop connector files integrates with Quickbooks" Those deleted files weren't specifically part of my git add, but because they already were tracked in git, I need to remove them from this branch's commit: $ git checkout -b ecc Instead of confusing those file deletions with ecc, I'll make a different cleanup branch later to reflect those files' deletion.ģ) I didn't follow my workflow! I forgot about git while I was trying to get ecc working again.īelow: rather than do the all-inclusive git commit -am "updated ecc package" I normally would, I only wanted to add the files in the /ecc folder. " to include in what will be committed)ġ) In the output you can see the changes from the ECC package's upgrade, including the addition of new files.Ģ) Also notice there are two files (not in the /ecc folder) I deleted independent of this change. " to discard changes in working directory) Note: the output below is snipped git is quite verbose. ![]() Git commit -am "updated form in contact module"īelow: actual usage, including explanations. My workflow of git commands: git checkout -b contact-form I updated a package to my website and had to go back to my notes to see my workflow I thought it useful to add an example to this answer. Another newb situation is getting current code, which still manages to elude me. If you are like me, and not a Git-guru, my answer here describes handling the deletion of files from git's tracking without deleting them from the local filesystem, which seems poorly documented but often occurrence. This reference complements the first one nicely with more of a focus on those less acquainted with git. (that link points to github's "network" visualization tool) And here is another great reference with illustrations. Using -no-ff allows someone reviewing history to clearly see the branch you checked out to work on. Until I saw this, I was completely lost with git. Here is a site with a clear explanation and graphical illustration of using git merge -no-ff: This way you can regularly do something like git pull -ff-only without thinking, and then if it errors out you can go back and decide if you want to merge or rebase. Similarly, if you want to execute a git pull or use git merge in order to explicitly fast-forward, and you want to bail out if it can't fast-forward, then you can use the -ff-only flag. In order to do that, you can pass the -no-ff flag and git merge will always construct a merge instead of fast-forwarding. you're merging in a topic branch and you want to ensure it looks that way when reading history). However, occasionally you want to prevent this behavior from happening, typically because you want to maintain a specific branch topology (e.g. This commonly occurs when doing a git pull without any local changes. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit. The -no-ff flag prevents git merge from executing a "fast-forward" if it detects that your current HEAD is an ancestor of the commit you're trying to merge. ![]()
0 Comments
Leave a Reply. |