n l i t e d

:



Thread Links
next

Branch Diff

📢 PUBLIC Page 1121:4/4 | edit | chip 2017-12-22 12:21:22
Tags: git

Dec 22 2017

I have been working on the "Work" branch for a while, finished adding some features, and now I want to see how far it has diverged from the "master" branch.

First I need to make sure everything has been either committed or thrown away.
git status .
Any files that I want to keep need to be added and committed. Everything else needs to be either deleted, added to .gitignore, or overwritten with the committed version.
git checkout -f -- file.txt

Only after the working directory is clean, I switch to the master branch.
git checkout master
Determine how many files have changed.
git diff --stat Work -- > Files.txt
Files.txt is now my ToDo list, I need to determine how each file changed and decide how to merge it into the master branch. I can do this the slow, methodical way by looking at each file individually or I can do it the fast, error-prone way by letting git do it for me.

Individual Merge

Get the text differences between the file in Work and the current version in master. In this example, DbgOut is the Work branch:
S:\Src\HQ\Dev\SB\Chip\VirtualDisk\CryptDisk\Bin>git diff DbgOut -- CreateZip.bat diff --git a/Bin/CreateZip.bat b/Bin/CreateZip.bat deleted file mode 100644 index 0a41cec..0000000 --- a/Bin/CreateZip.bat +++ /dev/null @@ -1,2 +0,0 @@ -@del CryptDisk.zip -@C:\Bin\7z\7z a -tzip CryptDisk.zip .\Out\%1\CryptDisk.exe .\Out\%1\CryptDriver2.sys .\Out\%1\CryptIFS.sys
In this case, the file exists only in the DbgOut branch. I need to decide whether to pull it into the master branch. If I don't need it, I do nothing. If I do want it, I merge it.
git checkout -p DbgOut -- CreateZip.bat git add CreateZip.bat git commit -m "Merged from DbgOut branch."
I can then view the commit log for the file across all branches.
git log --all CreateZip.bat

To selectively cherry-pick text edits I need to extract the Work version of the file and use an interactive merge tool (Epsilon, Araxis Merge, etc) to update the current version.
git show Work:./file.txt > file.txt.work
Use the merge tool to merge changes from file.txt.work into file.txt, then add and commit the merged version.
git add file.txt git commit -m "Merged changed from Work branch."

I can replace the master version of file.txt with the version from Work verbatim:
git checkout Work -- file.txt git add file.txt git commit -m "Replaced with the version from the Work branch."

Let Git Do It

The fast and easy way.
git checkout master git merge Work git push origin master

This works well when the master branch has remained static while Work changed, and git is able to simply "fast-forward" the master branch. But if there are any files that changed in master git will deposit merge markers in the files. I then need to merge these files before I can submit the changes.

Finish

Make sure everything has been committed, ignored, or deleted, or replaced.
git status . On branch master nothing to commit, working tree clean
The updated master branch is pushed to the upstream repo.
git push origin master
I need to decide how to deal with the Work branch. If it is a historical milestone like a product release, I leave it as-is and only use it for reference. If it was an experiment that has run its course, I should delete it.
git branch -d Work
To reuse the branch for further work on the master I need to reset it to mirror the current state of master. The easiest way to do this is by deleting and recreating the branch.
git branch -d Work git checkout -b Work
Or I can keep the branch and overwrite everything with master.
git checkout -f master --



close comments Comments are closed.

Comments are moderated. Anonymous comments are not visible to other users until approved. The content of comments remains the intellectual property of the poster. Comments may be removed or reused (but not modified) by this site at any time without notice.

  1. [] ok delete


Page rendered by tikope in 261.373ms