Changes between Initial Version and Version 1 of Basic Git Usage


Ignore:
Timestamp:
Jun 14, 2009, 3:54:46 PM (15 years ago)
Author:
Joe Ciccone
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Basic Git Usage

    v1 v1  
     1This page contains a basic tutorial for working with git. There aren't any advanced concepts here, just the basics. In this tutorial we'll be working with a testing git repo and fake files.
     2
     3Its always a good thing to remember that while working with Git is a decentralized VCS, even though you may choose to push changes all to one server, you don't have to. Each repo contains a full history and set of objects in the .git directory.
     4
     5You will also only see a .git directory in the top level unlike svn where you have .svn in each sub directory as well as the top level.
     6
     7Unlike svn, git uses hashes to identify commits instead of revision numbers.
     8
     9These are just some basic tasks, the man pages can go into a lot more detail.
     10
     11=== Initializing a Git Repo ===
     12
     13Create a empty working directory:
     14
     15{{{
     16mkdir git-tutorial
     17cd git-tutorial
     18}}}
     19
     20Initialize the local Git Repo:
     21
     22{{{
     23git init
     24}}}
     25
     26=== Committing files to the Repo ===
     27
     28Lets create a test file:
     29
     30{{{
     31echo "Test Data" > testfile
     32}}}
     33
     34Stage the file to be included into the next commit:
     35
     36{{{
     37git add testfile
     38}}}
     39
     40Finally commit the file to the repo:
     41
     42{{{
     43git commit -m "Add a test file"
     44}}}
     45
     46=== Viewing changes to files before committing them ===
     47
     48First lets make a change to our test file:
     49
     50{{{
     51echo "Different Test Data" > testfile
     52}}}
     53
     54View the changes:
     55
     56{{{
     57git diff
     58}}}
     59
     60You could also execute the following or something similar:
     61
     62{{{
     63git diff testfile
     64}}}
     65
     66=== Listing files with changes ===
     67
     68You can use the following command to list the status of all files not ignored by Git:
     69
     70{{{
     71git status
     72}}}
     73
     74You can also use the command on a path, the same as git diff.
     75
     76=== Revert a file back to a specified commit ===
     77
     78In this case we want to revert to the current working ref, so we wont specify one:
     79
     80{{{
     81git checkout testfile
     82}}}
     83
     84=== Reverting the entire working tree ===
     85
     86You can use the following command to revert the entire working tree to the last commit in the branch you're working with:
     87
     88{{{
     89git reset --hard
     90}}}