Updated:

Basic CLI

package app;

class App {
    public static void main(String[] args) {
        System.out.println("Hello World");
}

The above code can be run on command line

$ java app/App.java
>> Hello World

-d <directory> specifies where to place generated class files

$ javac -d ../bin/ app/App.java

cat lets you preview what is in the file

# Preview App.java file
$ cat Simple/src/app/App.java

diff lets you check the difference between two files

$ diff text1.txt text2.txt

Git

Creating and merging branches

Creating a branch named test

$ git branch test 

Changing current branch to test

$ git checkout test

Merging changes made in test into main

$ git checkout main
$ git merge test
$ git push origin main

Deleting branches

Deleting a branch

# Delete test branch locally
$ git branch -d test

# Delete test branch remotely
$ git push origin --delete test

Temporary revert to a previous commit

  • Creates a temporary branch that contains files committed with the given code
  • Committing changes to this branch will not alter the main branch
    $ git checkout 5f85982c81f05335cddd5fa952d4e2574825db4d
    

Creating a new branch that is reverted to a previous commit

  • test branch contains files committed with the given code
    $ git checkout -b test 5f85982c81f05335cddd
    

Excluding IDE files from Git

Use .gitignore

# Eclipse files
*/.classpath
*/.project
*/.settings

Git misc

  • git log shows the commits I have made
  • git commit -am "..." does both -a and -m
  • git restore --staged <filename> unstages the commit
  • Conflicts happen when remote is out of sync with the main branch. Decide which to keep and delete the conflicts, then merge again.

Tags:

Categories:

Updated:

Leave a comment