Add Commits To A Repo

1. create the Repo

1
$ git init new-git-project

2. move to correct project

1
$ cd new*

3. Chek Status (IMPORTANT!)

1
$ git status

4. Make Changes (Create Files)

1
2
$ touch index.html
$ open -a /Applications/Subli* index.html
1
2
$ mkdir css
$ touch css/app.css

5. Check Status Again

1
$ git status

img

6. Staging Files(git add)

6.1 Staging all files and directories

1
$ git add .

6.2 Staging specific files

1
2
3
$ git add <file1> <file2> ... <fileN>

$ git add index* css/app.css js/app.js

7. Check Status

1
$ git status

8. Make a Commitment

If not configured, configure it first

1
$ git config --global core.editor <your-editor's-config-went-here>

Commit it

1
$ git commit

Then open it in the code editor, Edit, save and close the file, then return back to the terminal

Note: you can directly add message with -m

1
$ git commit -m 'Initial commit'

Git Commit Recap

The git commit command takes files from the Staging Index and saves them in the repository.

1
$ git commit

This command:

  • will open the code editor that is specified in your configuration
    • (check out the Git configuration step from the first lesson to configure your editor)

Inside the code editor:

  • a commit message must be supplied
  • lines that start with a # are comments and will not be recorded
  • save the file after adding a commit message
  • close the editor to make the commit

Then, use git log to review the commit you just made!

9. git diff

see changes that have been made but haven’t been committed, yet:

1
$ git diff

10. Commit Message

书写建议

Udacity Style (For reference)

11. Having Git Ignore Files

the .gitignore file is used to tell Git about the files that Git should not track. This file should be placed in the same directory that the .git directory is in.

Step1: Add file .gitignore, in the same directory as .git

1
$ touch .gitignore

Step2: write the ignored file name in the .gitignore

1
$ open .gitignore

Add the following line in it.

1
2
3
4
project.docx

samples/*.jpg
# All the .jpg files in 'samples' directory

image-20180610202156014