Thursday, April 7, 2016

Learn Git_Lesson_Basic Git Workflow


1.Hello Git
  • Git is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed.
In scene-1.txt, add this text: 

Harry Programmer and the Sorcerer’s Code: Scene 1
    • In the terminal, initialize a new Git project. 
    2.git init
    git init
    The word init means initialize. The command sets up all the tools Git needs to begin 
    tracking changes made to the project. 
    Notice the output:  
    
    Initalized an empty git repository in /home/ccuser/workspace/sorcerers-code/.git/
    The Git project was created. 
    3.Git Workflow
    • A Git project can be thought of as having three parts:

    1. A Working Directory: where you'll be doing all the work: creating, editing, deleting and organizing files
    2. A Staging Area: where you'll list changes you make to the working directory
    3. A Repository: where Git permanently stores those changes as different versions of the project
    The Git workflow consists of editing files in the working directory, adding files to the staging area, and saving changes to a Git repository.
    4.git status
    • As you write the screenplay, you will be changing the contents of the working directory. You can check the status of those changes with: 
    $ git status
    Output:
    On branch master                                                                                                                                                                                
    Initial commit                                                                                                                                                                         
    Untracked files:                                                                                 
      (use "git add <file>..." to include in what will be committed)                                                                                                                              
            scene-1.txt                                                                                                                                                                              
    nothing added to commit but untracked files present (use "git add" to track)  
    In the output, notice the file in red under untracked files. Untracked means that Git sees the file but has not started tracking changes yet.  
    5.git add
    • In order for Git to start tracking scene-1.txt, the file needs to be added to the staging area. We can add a file to the staging area with:
    $ git add filename
    
    The word filename here refers to the name of the file you are editing, such as scene-1.txt.
    $ git add scene-1.txt                                                                            
    $ git status                                                                                     
    On branch master                                                                                                                                                                               
    Initial commit                                                                                                                                                                               
    Changes to be committed:                                                                         
      (use "git rm --cached <file>..." to unstage)                                                                                                                                                  
            new file:   scene-1.txt
    In the output, notice that Git indicates the changes to be committed with "new file: 
    scene-1.txt" in green text. Here Git tells us the file was added to the staging area. 
    6.git diff 
    • Imagine that we type another line in scene-1.txt. Since the file is tracked, we can check the differences between the working directory and the staging area with:
    $ git diff filename
    In the code editor, add this text to scene-1.txt:
    Dumblediff: I should've known you would be here, Professor McGonagit.
    From the terminal, use the new command to check the difference between the working directory and the staging area.
    Notice the output:

    • "Harry Programmer and the Sorcerer's Code: Scene 1" is in the staging area, as indicated in white.
    • Changes to the file are marked with a + and are indicated in green.
      IMPORTANT: press q on your keyboard to exit diff mode. 
    $ git diff scene-1.txt                         
    diff --git a/scene-1.txt b/scene-1.txt         
    index c33ce4c..2d6e91a 100644                  
    --- a/scene-1.txt                              
    +++ b/scene-1.txt                              
    @@ -1 +1,2 @@                                                                                                                            
    -Harry Programmer and the Sorcerer’s Code: Scene 1                                                          
    +Harry Programmer and the Sorcerers Code: Scene 1                                                           
    +Dumblediff: I should've known you would be here, Professor McGonagit. 
    Add the changes to the staging area in Git. Recall that you will need to identify the file by its name.
    $ git add scene-1.txt  
    7.git commit 
    • A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository. git commit is the command we'll do next. However, one more bit of code is needed for a commit: the option -m followed by a message. Here's an example:
    $ git commit -m "Complete first line of dialogue"
    
    
    
    Standard Conventions for Commit Messages:
    1. Must be in quotation marks
    2. Written in the present tense
    3. Should be brief (50 characters or less) when using -m
    $ git commit -m "Complete first line of dialogue"                                                
    [master (root-commit) 4e4fa51] Complete first line of dialogue                                   
     1 file changed, 2 insertions(+)                                                                 
     create mode 100644 scene-1.txt  
     8.git log
    • Often with Git, you'll need to refer back an earlier version of a project. Commits are stored chronologically in the repository and can be viewed with:
    $ git log
    From the terminal, log a list of your commits.
    
    In the output, notice:
    
    • A 40-character code, called a SHA, that uniquely identifies the commit. This appears in orange text.
    • The commit author (you!)
    • The date and time of the commit
    • The commit message
    $ git log                                                                                        
    commit 4e4fa51c9da73506d7eb2d8e931f803939039298                                                  
    Author: codecademy <ccuser@codecademy.com>                                                       
    Date:   Thu Apr 7 21:00:41 2016 -0400                                                                                                                           
        Complete first line of dialogue
    9.git Generalizations 
    Summary:
    • Git is the industry-standard version control system for web developers
    • Use Git commands to help keep track of changes made to a project:
      • git init creates a new Git repository
      • git status inspects the contents of the working directory and staging area
      • git add adds files from the working directory to the staging area
      • git diff shows the difference between the working directory and the staging area
      • git commit permanently stores file changes from the staging area in the repository
      • git log shows a list of all previous commits
    
     

    No comments :

    Post a Comment