Working with git locally.

Figure 370. Initialize git project Slide presentation Create comment in forum
  • git init

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


Figure 371. Configure author related data. Slide presentation Create comment in forum

Figure 372. Adding resources to project index and staging area Slide presentation Create comment in forum
  • git add Math.java

  • Result: New files will show up upon invocation of git status.


Figure 373. Committing change set Slide presentation Create comment in forum
  • git commit --message "New math class containing single method"

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


Figure 374. Project versioning status Slide presentation Create comment in forum
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 375. Adding a comment Slide presentation Create comment in forum
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 376. git diff tracing changes Slide presentation Create comment in forum
git diff tracing changes

Figure 377. Reverting individual file. Slide presentation Create comment in forum
>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 378. Compiling, Math.class and Print.class. Slide presentation Create comment in forum
> 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 379. Math.class, Print.class and versioning. Slide presentation Create comment in forum
  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 380. Show project's log Slide presentation Create comment in forum
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 381. Switch to an older revision ... Slide presentation Create comment in forum
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 382. ... and forth to current master's HEAD Slide presentation Create comment in forum
git checkout master
Previous HEAD position was 7f119fa Project Readme.md
Switched to branch 'master'

exercise No. 120

git local, DIY Create comment in forum

Q:

Repeat the current example using your own workspace.