Working with git locally.

Figure 376. Initialize git project Slide presentation
  • git init

  • Result: Sub folder .git containing project's metadata and versioning history


Figure 377. Configure author related data. Slide presentation

Figure 378. Adding resources to project index and staging area Slide presentation
  • public class Math {
    
      static public int add(
       final int a, final int b) {
         return a + b;
      }
    }
  • git status: Math.java yet unversioned.

  • git add Math.java

  • git status: Math.java became versioned.


Figure 379. Committing change set Slide presentation
  • git commit --message "New math class containing single method"

  • Result: Commit change set to repository adding given message to project log.


Figure 380. Project versioning status Slide presentation
git status
On branch master 

No commits yet 

Untracked files: 
  (use "git add <file>..." to include in what will be committed)

    Math.java

nothing added to commit but untracked files present (use "git add" to track) 

Our project currently has got only one branch. See basic branching for further details on possible project branches.

Committing resources is an active task. We have not yet performed any commit.

We have added a file Math.java to our project's main folder but it has not (yet) been added to git versioning.

Friendly hint how to proceed.


Figure 381. Adding a comment Slide presentation
public class Math {

  static public int add(
   final int a, final int b) {
     return a + b;
  }
}
public class Math {
 /**
  * Summing two int values.
  * @param a first value.
  * @param b second value.
  * @return The sum of both.
  */
  static public int add(
   final int a, final int b) {
     return a + b;
  }
}

Figure 382. git diff tracing changes Slide presentation
git diff tracing changes

Figure 383. Reverting individual file. Slide presentation
>git checkout --  Math.java 

>git diff Math.java 
>

Double dashes '--' disambiguating branch names from file names.

Replace working tree file Math.java by repository master.

No difference working tree to master branch.


Figure 384. Compiling, Math.class and Print.class. Slide presentation
> javac Print.java Math.java  # Compilation creating Math.class and Print.class
 
> git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Math.class
        Print.class

nothing added to commit but untracked files present (use "git add" to track)

Figure 385. Math.class, Print.class and versioning. Slide presentation
  1. Math.class and Print.class are being generated from Math.java and Print.java.

  2. Rule of thumb: Do not version dependent objects.

Solution: Add a .gitignore file to versioning to contain:

# ignore generated .class files
*.class

Figure 386. Show project's log Slide presentation
git log
commit 0137ccd857a242f4751e36bdbce365c6130c3a32 (HEAD -> master) 
Author: Martin Goik <goik@hdm-stuttgart.de>
Date:   Sat May 25 11:56:00 2019 +0200

    Removing duplicate headline 

commit 7f119fac36e02e4c5a7f04f022217b6f744d6e1d 
Author: Martin Goik <goik@hdm-stuttgart.de>
Date:   Sat May 25 11:49:52 2019 +0200

    Project Readme.md  ...

Latest commit among with its hash value.

Latest commit message.

Previous commit among with its hash value.

Previous commit message.


Figure 387. Switch to an older revision ... Slide presentation
git checkout 7f119fac36e02e4c5a7f04f022217b6f744d6e1d
Note: checking out '7f119fac36e02e4c5a7f04f022217b6f744d6e1d'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 7f119fa Project Readme.md

Figure 388. ... and forth to current master's HEAD Slide presentation
git checkout master
Previous HEAD position was 7f119fa Project Readme.md
Switched to branch 'master'

exercise No. 126

git local, DIY

Q:

Repeat the current example using your own workspace.