Nitesh Turaga
Fri Mar 2 14:15:59 2018
Before git add
git diff
after git add
git diff --cached
after git commit
git diff --staged
between commit and HEAD
git diff <commit_hash>
Commit code whenever you have made a single logical change. Allows for writing concise but descriptive commit messages
Small and frequent commits allow functionality to isolate bugs,
git bisect
When to use a feature branch
You will be committing “work in progress” changes to save progress that leave your application in a broken state and shouldn’t go to production
There will take multiple logical changes to the codebase that are part of a larger project
There will be several commits in a row that all depend on each other and should be in order
When you don’t need a feature branch
(*i.e it’s okay to commit to master)
You’re making a small change that fits nicely inside one commit
Bug fixes/hot fixes for fixing typos, etc
Previous/future commits won’t affect this commit
If the “small” changes on a master branch get out of hand,
consider,
git stash
git checkout -b new-feature
git stash apply {1}
Every commit message should describe why the code was changed – or what a change accomplished – at an appropriate level of detail
Here are some code smells or signs that you’ve writing a bad commit message:
If you have a bad commit message
git commit —amend
The commit message has a “title” and “paragraph”
Eg:
Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together
Refer to this link on how to write good commit messages:
https://chris.beams.io/posts/git-commit/
Good way to check commit history, (see all the titles of commits)
git log --oneline
At a minimum, every commit should atleast
build
R CMD build <package>
install
R CMD INSTALL <package>
Merge commits with master only if they work, otherwise keep them on the feature branch.
If you have trouble merging conflicts, a good way to merge branches is using
git mergetool
Advantages,
GUI opens up to see where the diff occured
Click and choose HEAD vs commit
Quick look at remotes
origin git@github.com:Bioconductor/mypackage (fetch)
origin git@github.com:Bioconductor/mypackage (push)
upstream git@git.bioconductor.org:packages/mypackage (fetch)
upstream git@git.bioconductor.org:packages/mypackage (push)
Start with master branch
(make sure master is synced with git@git.bioconductor.org)
git checkout master
git fetch --all
git merge upstream/master
git merge origin/master
Once synced, checkout a new feature branch
git checkout -b new-feature
add and commit changes
git status
git add <some-file>
git commit
push new feature branch to remote( github only)
-u create a new branch on github
git push -u origin new-feature
NOTE: once the new-feature branch is created, subsequent push(s) will be
git push origin new-feature
merge with master (github)
git checkout master
git pull (or) git fetch / merge
git merge new-feature
push github master to Bioconductor master
git checkout master
git push upstream master
git push origin master
Eg:
https://github.com/Bioconductor/RGalaxy/pull/1
– Reviewer
– Leave comments if needed on the code and review
– Make sure the author of the PR did a version bump as well.
If not,
Command line options:
git checkout -b <user-master> master
## Change DESCRIPTION file for version bump
git add
git push
– Push to both Github and Bioconductor
– Leave comment at the end, saying what issue the PR deals with
(Pro tip: You can say “Closing #1” to reference a issue and close)
Squash commits in the feature branch if you have a large number of commits
Eg: This resets, the last 30 commits from HEAD
git reset --soft HEAD~30
Add a new commit message which is meaningful as a summery for the last 30 commits
git commit -m "New message for the combined commit"
git push