Git Notes.

Notes on Git.

Git is a distributed source control system.


Repository lives in the folder itself.

Repository
Where your files and their history are stored, the database.

Working Set
The current state of the files as stored on your local machine.

Add
Inserting new files from Working Set to Repository.

Check-In (Commit)
Copying changes from Working Set to Repository.

Check-Out (Update)
Copying changes from Repository to Working Set.

Tag (Label)
Marking the current state of the repository for future checkouts. This is usually a "well known" state.
It is best to tag feature by feature or version by version.

Revert (Rollback)
Overwriting files in your Working Set from Repository.

Push / Pull
Exchanging changes between Repositories. You can also Export / Import your Repository.



Branching (Forking)
Making a clone of a Repository. (The files are not really copied, just another branch is monitored by the system.)

Merging
What you branch (or fork) from is called the Main Branch or the Trunk. After applying changes in the Branch,
you merge your branch into the Main Branch.

Example

git init
This will create a new Repository in the folder where you run the command.
Git stores data about your files in a hidden folder called .git.

git status
Verify that repository is initalised.

! Create a new file called myprog.c and add main function in it.

git add *
Add the file to Working Set.

git commit -a -m "Adding myprog.c"
File is commited to the repository.
-m "Adding myprog.c" is just a commit message.

git log -p
Shows the log of the commits.

! Reopen myprog.c and add another function to it.

git commit -a -m "Add Func1()"
Commit the changes to the Repository.

! Reopen the file and add another function.

git commit -a -m "Add Func2()"
Commit the changes to the Repository.

git log --oneline --all

See logs in a better and cleaner way.
This will also show ids, something like this:
45654 Add Func2()
dd234 Add Func1()
6a45g Adding myprog.c

git diff 6a45g 45656
This will show us the differences between the 2 commits.

! Open the file and delete Func1()

git diff
This will show the difference between the Repository and the Working Set.

Something like this will be seen on screen:
-Func1()
the minus sign indicating Func1() line is removed.

If there are additions in your Working Set, you will something like this:
+NewFunctionHere()

git commit -a -m "Delete Func1()"

! Open the file and create Func3()

git commit -a -m "Add Func3()"

git log --oneline --all
See logs in a better and cleaner way.
This will also show ids, something like this:
4b8ed Add Func3()
61ee5 Delete Func1()
45654 Add Func2()
dd234 Add Func1()
6a45g Adding myprog.c

! Delete Func3(), assume by mistake!

git checkout myprog.c
We checked out the file from the Repository so Func3() is back!

or..
git checkout HEAD myprog.c

Notes:
git diff
will show you changes in the working directory that are not yet staged for the next commit.

git diff HEAD
shows changes in the working directory since your last commit; what you would be committing if you run "git commit -a".