… all meaningful operations can be expressed in terms of the rebase command. Once you figure that out it all makes sense.
~ Linus Torvalds
Andrew Briening (abriening)
You are probably...
You should know when and why any changes were made.
This requires a clean history.
But what does that realy mean?
When are you cleaning history, or destroying it?
We'll come back to this later …
SVN publishes the recommended usage in their Svnbook.
Git on the other hand …
%> man git
GIT(1)
NAME
git - the stupid content tracker
...
We'll come back to this later …
Use svn update
to pull-down the changes from the remote and apply them to your local working copy.
%> svn update
Updating '.':
Conflict discovered in 'sandwich.txt'.
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
C sandwich.txt
Updated to revision 2.
Summary of conflicts:
Text conflicts: 1
This usually leaves a messy set of conflicts if you have uncommitted changes.
You then resolve all of the conflicts and attempt to commit again.
The friendlier technique outlined in the book is to use svn status -u
to review the upstream files/commits.
svn status -u -v
M * 44 23 sally README
M 44 20 harry bar.c
* 44 35 harry stuff/trout.c
D 44 19 ira stuff/fish.c
A 0 ? ? stuff/things/bloo.h
Status against revision: 46
This allows you to then update and resolve files one at a time using svn update stuff/trout.c
.
git branch --merged
to see if a branch is in mastergit merge
Don't merge upstream code at random points
Don't merge downstream code at random points either
… all meaningful operations can be expressed in terms of the rebase command. Once you figure that out it all makes sense.
With a feature branch:
* 3dcd585 Adding Comment model, migrations, spec
* 9f5c362 Adding Comment controller, helper, spec
* dcd4813 Adding Comment relationship with Post
* 977a754 Comment belongs to a User
* 9ea48e3 Comment form on Post show page
It will get merged as one commit with a message like:
[#3275] User Can Add A Comment To a Post
* Adding Comment model, migrations, spec
* Adding Comment controller, helper, spec
* Adding Comment relationship with Post
* Comment belongs to a User
* Comment form on Post show page
Modified git-flow without the extensions.
git datetag
release-2012-12-11T01.39.50
Modified git-flow without the extensions.
What about long-lived branches?
Don't use long-lived branches
No, really, what about long-lived branches?
microcosm/next » ancestor of master
microcosm/feature-456 » decendent of microcosm/next
microcosm/bug-123 » decendent of microcosm/next
microcosm/integration » throw-away integration
Some tools & techniques to keep you safe while merging & rebasing.
To test the interaction of several topics, merge them into a throw-away branch. You must never base any work on such a branch!
If you start using throw-away integration branches then git rerere
will be your new best friend.
%> git merge i18n-world
Auto-merging hello.rb
CONFLICT (content): Merge conflict in hello.rb
Recorded preimage for 'hello.rb'
Automatic merge failed; fix conflicts and then commit the result.
%> git add hello.rb
%> git commit
Recorded resolution for 'hello.rb'.
[master 68e16e5] Merge branch 'i18n'
git merge --no-ff
You can always make more branches.
git checkout -b feature-123-b feature-123
git rebase master
And ther is always the reflog
git reflog
b64f807 HEAD@{0}: commit: Silence warning about VERSION...
a2083ca HEAD@{1}: commit: Adds gem dependency on json 1...
adc1095 HEAD@{2}: commit: Adds backup example
ef1c4ab HEAD@{3}: commit: Updates validations & error m...
cf681af HEAD@{4}: commit: Updates validations & error m...
e97f1f3 HEAD@{5}: commit: Updates carpenter binary to e...
d9ac66a HEAD@{6}: checkout: moving from validation_unit...
3322ef8 HEAD@{7}: commit: Unit tests for validation
d9ac66a HEAD@{8}: checkout: moving from experimental to...
d9ac66a HEAD@{9}: checkout: moving from d9ac66a69cabee1...
d9ac66a HEAD@{10}: pull : Fast-forward
c5bd0ab HEAD@{11}: merge allow-alternate-definitions-di...
git reset --hard a2083ca
git stash; git stash pop
git save; git restore
# .gitconfig
[alias]
save = !git add . && git commit -a -m"WIP"
restore = !git reset --soft HEAD^ && git reset
Pay attention & be safe.