[Fixed]-Git- understanding the output of diff command

1👍

git diff budgetsReports3 master can be read as “What changes need to be made to budgetsReports3 to make it look like master

A nice resource for understanding diffs is https://www.git-tower.com/learn/git/ebook/en/command-line/advanced-topics/diffs

0👍

I currently have a number of branches of development- and want to merge some of the changes on my current branch with the master, but don’t want to merge all of the changes from this branch.

As long as you want to merge only some changes (and not others) from one branch to another, merge by itself is not the tool to use (in git anyway). In git, a merge means everything in this branch has been merged into the other branch.

There are a few ways to proceed:

  1. A merge based workflow: Use git rebase -i to rewrite the history of your budgetsReports3 branch so that the changes you want to merge are self contained in one or more commits before all the other commits. Then merge just those commits to master. And probably merge master into budgetsReports3.

  2. A rebase based workflow: Rewrite budgetsReports3 (as in 1) but then rebase budgetsReports3 on master. Then merge the self contained commits to master. This will be a fast forward merge.

  3. A diff based workflow: Take the git diff (in the other direction), use git apply to apply it to master, use git add -p to add only some of the diffs, commit, and rebase budgetReports3 on top of master. For example:

    git checkout budgetsReports3  # if not already there
    git diff master budgetsReports3 -- costing/views.py > views.diff
    git checkout master
    git apply views.diff
    git add -p costing/views.py  # follow the prompts to choose which patch hunks you want to apply
    git commit -m "your message"
    git reset HEAD costing/views.py
    git checkout costing/views.py
    git checkout budgetsReports3
    git rebase master
    

Personally, I prefer rebase based workflows, but that’s up to you. Also note that if you have already shared (you have pushed or someone else has pulled) your budgetsReports3 branch to another repo, rebase is not advised (unless you really know what you’re doing).

Leave a comment