The GUI tool has menu options to get to the gitk tool, but you can get it by gitk also

.gitignore

To ignore files, you can use .gitignore.

Patterns are read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.

If you want to see what you would be committing (i.e. the diff between HEAD and the index):

git diff --cached

What is different between the index and the local working copy files

git diff

git diff-files --name-status tells you just what files are changed

git whatchanged -p shows a patch diff of past history

git reflog shows you when the tip of the branch changed

git diff origin/master..master tells what I changed from the remote repo

If you setup an external diff viewer, this provides a GUI editor of the diff

gitk origin/master..master will show the diff in gitk

git diff --no-ext-diff disables the external diff viewer

If you have two branches A and B, both started at a same common commit, but since then both have diverged differently, you can use the "triple dot" notation to see how they both diverged:

gitk A...B

If I don't want to pull from the remote, but I want to see what changed up there:

git fetch origin <branch>

git diff --name-only origin/<branch>

git diff origin/<branch>

Checkout

To checkout an old version (this example gets the one from the previous commit):

git checkout HEAD^ path/to/file

git show HEAD^ path/to/file just shows the file, but doesn't check it out

Patches

Create a patch for all commits that are different from origin that can be emailed

git format-patch --stdout origin

Create a patch for the last commit just performed on the current branch

git format-patch --stdout HEAD^1..HEAD

Apply a series of patches from emails

cat ...output from format-patch... | git am

Apply a diff to working copy and index (not committed)

git apply ...diff.patch...

Send the patch via email

git format-patch --stdout origin > my.patch
git send-email my.patch

For this to work, your .gitconfig has to have SMTP setup

[sendemail]
smtpserver=your.smtp.hostname

Branching

To see what local branches are in the repo, and which one your working copy is currently on:

git branch

To create a new branch

git branch <name of new branch>

To switch to a branch

git checkout <name of branch>

How to checkout a "tracking" branch that tracks a remote branch which you can push to/pull from

git checkout --track -b branch_name origin/branch_name

If you already have a local branch but you want to push it up to the remote repo

git push origin the-name-of-your-local-branch

How you can create your own remote branch and begin working in it

git push origin master:refs/heads/experimental
Create the branch experimental in the origin repository by copying
the current master branch. This form is only needed to create a new
branch or tag in the remote repository when the local name and the
remote name are different; otherwise, the ref name on its own will
work.

To delete a branch (usually done after you merge into master and no longer need the branch)

git branch -d <name of doomed branch>

To delete a remote branch (dangerous!)

git push origin :doomed-branch-name

To merge a branch, you checkout the one branch, and ask to merge the second

git merge <name of branch to merge into working copy>

git reset allows you to revert back if a merge has too many conflicts

Rebasing means you just move the base of your working copy to a given branch

You must have everything added/committed to your index

git rebase <branch to base the working copy on>

If you are working on something and don't want to commit to your branch, but need to switch to another branch, you can stash your changes. After you switch to the other branch, finish doing what you need and switch back, you can apply your stash getting back to the way you were before

git stash

git stash apply

You can see what you stashed using the options "list" and "show" to git stash

You can peek at what a remote repo changed without merging first, using the "fetch" command; this allows you to inspect what someone else did, using a special symbol "FETCH_HEAD", in order to determine if there is anything worth pulling, like this:

git fetch /home/bob/myrepo master
git log -p HEAD..FETCH_HEAD

This operation is safe even if you have uncommitted local changes. The range notation "HEAD..FETCH_HEAD" means "show everything that is reachable from the FETCH_HEAD but exclude anything that is reachable from HEAD".

If you want to visualize this: gitk HEAD..FETCH_HEAD

If you want to push a small subset of commits excluding others you might also have:

git pull --rebase (paranoia, just make sure you have everything up to date)

git cherry-pick SHA (cherry pick over things you want to push out)

git push origin HEAD:master (pushes the current branch to the remote ref matching master in the origin repository. This form is convenient to push the current branch without thinking about its local name)

Tagging

You can tag a branch, usually to denote a release

git tag -a <tag name>

TODO: how do you switch to or checkout a tag???

Bisecting

Use "git bisect" to hunt down when a bug was introduced in the code base.

You bisect the code, test and tell git if the test was good or bad. git helps track down the commit that caused the error.

To run a VM with JMX remoting enabled without authentication, you must pass in the following environment variables:

-Dcom.sun.management.jmxremote.port=19988

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false

To run a VM with JMX remoting enabled with password authentication:

-Dcom.sun.management.jmxremote.port=19988

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=true

-Dcom.sun.management.jmxremote.password.file=/some/directory/jmxremote.password
Note that "jmxremote.password" must be read-only. On Windows, you must use "cacls" command to do this: cacls /some/directory/jmxremote.password /P username:R
A password file template is located at $JRE_HOME/lib/management/jmxremote.password.template.
There is also an auth file that you can use to define other roles.
For more information on setting this up and setting up SSL, see http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html.

To run JBossAS 4 with JMX remoting enabled and with platform MBeans exposed via JNP too, pass in these extra variables:

RHQ Test Scripts

Here is a test script used to run the agentspawn stuff on multiple boxes that have an NFS directory on mulitple servers. Create an "agents" directory and put the following script in it, named runspawn.sh:

Checkout or copy the agentspawn module in here. Then create a directory called properties-files and in there put copies of agentspawn.properties in there (name them agentspawn.properties.<hostname>. Each of those properties files can be customized for the agents that will be spawned on that host (you probably will want to change the vm.dir and the starting ports). Now you can run that script, giving it the hostname as the first argument and the ant target as the second. Here's what the file/directory layout should be:

This produces "rhq/trunk/dev-container". Now you can run copy-servers.sh to copy the distros for the different hosts. delete-servers.sh will purge all the distros. run-server.sh will run the proper distro, assuming your server distros are put into directories with the same name as their host (i.e. "hostname -s").

To merge in a change from trunk into a branch, or vice versa (from a branch to a trunk), or even from one branch to another branch, you just do the same "svn merge -c" command from above, only you don't put a minus sign in front of the rev. First, you need to make sure the destination branch/trunk is checked out and is your current working copy. Then you basically say, "I want to merge into my working copy the changes introduced by revision ### of <svn URL>:

svn merge -c ### <svn URL>

Note that the working copy where your current directory is will get the newly merged code. You then commit your working copy.

Suppose we build a GA distribution from trunk (svn rev 100) and create a tag off of svn rev 100 called 1.0.GA. We've since moved forward on trunk with lots of new commits - we are up to svn rev 300 now. Now suppose we need to patch the 1.0.GA product. The fix for the patch was already committed to trunk, it was committed in svn rev 150. How can we apply the fix to the 1.0.GA.

Note that because its a single rev, we could have used "-c 150" instead of "-r 149:150"

Do a svn diff to double check you did it right and picked up the changes you need

Finally, checkin the fix: svn commit
At this point, your branch is now 1.0.GA with the patch and only that patch.

Do get a file that was deleted from SVN, you have to use svn log --verbose to find out which revision deleted it, then you svn up -r <rev minus one> file.txt to retrieve the file. Note that this means you need to have some working copy on your file system to do the svn log and svn up commands using these commands. You might be able to pass URLs to the commands if you don't have a working copy.

Miscellaneous Notes

Calculating number of resources in a hierarchy tree based on arbitrary levels

Remove Target Directories Manually

find . -name target -print | xargs rm -rf

SQL INNER JOIN, LEFT JOIN, RIGHT JOIN

Joins can be thought of in the context of a Venn diagram. You have two circles - A and B. They overlap in some parts.

The overlap is your INNER join - only the elements in A that also have associated B elements.
The A circle is the LEFT join - all A elements regardless of whether they have associated B elements.
The B circle is the RIGHT join - all B elements regardless of whether they have associated A elements.

Setting Time on UNIX Machines

If you have a set of UNIX machines and their clocks are not NTP-synced, use the "date" command to set their clocks to within a second or two to each other. To get the time of one machine in the format that "date" needs to set the clock, run this:

echo date `date +%m%d%H%M%y.%S`

Take the result of that and run it on the rest of the machines.

Rounding Integers

If you want to round something to thousands (like 103023 to 103000 or 103998 to 104000):

long l = (long) ((number / 1000.0) + 0.5) * 1000;

More generically, replace 1000.0 with the specific size you want:

long l = (long) ((time / specifiedLimit) + 0.5) * specifiedLimit;

Calculating Running Average

To read image metadata use "exiftool"

Testing Multicast

If you aren't sure a box has multicast enabled, run the following JGroups test app. This will run the receiver - it will print to stdout when it hears a multicast:

Sample Standalone Hibernate/JPA

Attached is a standalone Hibernate/JPA application\ based off of the Hibernate/JPA Hello World sample app. Build it with "ant package", then run the executable jar via "java -jar build/helloworld.jar". Type "help" at the prompt for the commands you can use to insert, delete and query the database. The database is Hypersonic using its in-memory feature - no database files or data will be persisted. There are two Hibernate/JPA entities - hello.Message and hello.Person. You can insert, delete and query them via the "add", "delete" and "get" commands. Note that if you want to use the RHQ hibernate plugin to manage it via jmx remoting, you have to set some system properties to configure the VM:

Sample Standalone JMX App

Attached is a very small sample JMX App\. It contains a prebuilt jmxapp.jar plus the source and an ant script to build the jar. It has a "runjmxapp" script that you can use as the command to start the JMX app. All it does is register a few MBeans to the platform MBeanServer and wait until the VM is killed. One MBean's name is a hardcoded static name, and the others have names that are partially determined at runtime. Use this when you need to test connectivity to a remote JMX MBeanServer.

Convert Epoch Milliseconds To Date

Attached is a small executable jar that converts epoch milliseconds to date strings\. To can convert in either direction (epoch millis to date or vice versa). Enter java -jar epochmillis.jar for usage help. You can put more than one argument on the command line to convert more than one value:

Running JBossAS Servers Bound To Different IP Addresses

Confluence Recently Updated not updating

Ran into an issue where the section on the main dashboard page called Recently Updated was not updating. To fix this, go to Administration>Content Indexing and rebuild the search index.

JBossTM/Arjuna Notes

Periodically, the recovery manager will ask the resource (e.g. the database), "what transactions do YOU know of that are pending and need to be recovered?". This is because the database also has the ability to mark a transaction as "prepared and waiting for a conclusion". It asks this independently of what the resource manager itself thinks is pending - i.e. the RM tries to recovery both transactions it knows of in its object store (top-down recovery) as well as transactions the database knows of (bottom-up recovery). It needs an XAResource to ask this. This is why in Oracle you need to grant some select permissions to the datasource's user - because the database's pending transactions are stored in special dba tables and its those tables the RM looks at to determine what is pending in the database.

There is a way to plug in a custom object store implementation. The object store stores transaction logs that include information about transactions that are in the 2PC stage. Out of box impls include database object store and filesystem object store (which is used out-of-box of JBossAS, and its stored in data/tx-object-store). You can write an in-memory store implementation - but you have to make sure we only store a finite size of data to avoid OOM or just throw the logs away (but if we do that, why bother? just don't use XA). There is no config prop to say, "don't log" - you have to write your own object store impl to do that.

1PC is on by default if there is a single resource enlisted in a transaction (no prepare phase), even if its XA. NO LOGS ARE WRITTEN when a single resource is enlisted.

Performance: XA vs. Local-Tx - there are additional round trips in XA - the 2PC protocol has the prepare, et. al. phases that introduce about 3 to 4 additional round trips every transaction.

The # of resources enlisted in a transaction matter, not what type the resources are (XA va. non-XA). If 2+ resources are enlisted, a log is written out and 2PC is attempted. If one is a local-tx, then a wrapper around its resource is provided that "simulate" an XA resource - but during the 2PC prepare phase, the prepare is a no-op in that wrapper. Note that when 2+ resources are enlisted, logs are written to the object store, even if they aren't XA.

"SELECT formatid, globalid, branchid FROM SYS.DBA_PENDING_TRANSACTIONS" is executed every X seconds (defined by com.arjuna.ats.arjuna.recovery.periodicRecoveryPeriod which defaults to 120).

com.arjuna.ats.arjuna.coordinator.txReaperTimeout (set to 120000) is for tx timeouts. As per "jhalliday", "actually its on-demand now, although periodic is still a config option. it wakes up, looks for live tx that have reached their allotted max lifetime and rolls them back. it actually won't touch ones that have been prepared, only the ones that have not reached that stage yet."

If the recovery fails, the resource manager continues to attempt to recover (unless a very specific set of errors are seen, in which case the RM knows the transaction is lost forever and no longer attempts it). You should be able to configure an expiration time - when this times out, the expiration code will remove the tx logs from the object store and stop trying to recover that tx. There is a bug currently in JBossTM in which that expiration never happens: https://jira.jboss.org/jira/browse/JBTM-418

Linux/Fedora Notes

ifcfg-eth0 - default settings when you switch to this device. I set PEERDNS=no which seems to tell network manager that I don't want my router to be considered a DNS server (PEERDNS=yes added 192.168.0.1 to my /etc/resolve.conf, which I did not want)

If some network connections but not all, and everything else is eliminated, try to lower the MTU setting on the network interface (I had to do this on a virtual machine guest) :

ifconfig eth0 mtu 1000

The "thread-max" kernel setting

To find out what the current max threads limit is: sysctl -a | grep threads