On [the Git] Note Ch2

Git second chapter of Part One study notes, including access to Git save library (Repository) as well as part of the basic command git


Get Git save library (Repository)

The method can be divided into two types, namely "the establishment" and "obtain"

  • Created: execute git init; currently one folder can be saved git repository established under the file system.
$ git init
  • To obtain: performing Git git clone can be copied on the remote server (Clone) to the local side. (Hereinafter the project on git hub, for example)
$ git clone git://github.com/schacon/grit.git

This command will create a directory to hold grit, if you want to specify the name of the directory, you can want to end the local directory name in the command plus:

$ git clone git://github.com/schacon/grit.git mygrit

Git is made on the server side all copies of the data . The project in the history of all versions of all files are executed pull back after git clone operator. If the server's disk drive fail, users can use any copy of a client server to restore the state to obtain a copy of the original .

Save the library to perform the update Git (Repository)

Git save the file in the library can be divided into several states, are explained as follows:

  1. No trace (Untracked): to save the file has been thrown into the library, but the file was not chase vertical
  2. Not Modified (Unmodified): vertical file has been chasing, but not modify
  3. Modified (Modified): the file has been modified, and the contents of the recorded different git
  4. Has been staging (Staged): After Git add command, Git staging file has been saved with the current local libraries same end; staged files will be formally recognized its implementation of changes in the next git commit.

  • Object file status shown
$ git status

Tracking new files (by the untrack into staged)

  • $ Git add test.txt (designated file)
  • $ Git add. (All transaction documents added stage) 

Note: after (. Git add) if a new file is added to the git, but modified for the file, you will find:

The files exist in staged, but there are cases where not staged (modified) at the same time, when in fact there are two documents to git, one that has been staged in text2.txt its contents at the time when the execution git add, and after modifying the local repository file.

Ignore certain file

This file can be added .gitignore in local repository, so that the rule git batch file with the default deemed not tracked. This file can be written content as follows:

# 注解,会被忽略。

# 不要追踪文件名为 .a 结尾的文件

*.a

# 但是要追踪 lib.a,即使上方已指定忽略所有的 .a 文件

!lib.a

# 只忽略根目录下的 TODO 文件。 不包含子目录下的 TODO

/TODO

# 忽略build/目录下所有文件

build/

# 忽略doc/notes.txt但不包含doc/server/arch.txt

doc/*.txt

# ignore all .txt files in the doc/ directory

doc//*.txt

Check the file changes

  • Diff Git : Git Diff default without parameters than the current working directory (working directory) and the temporary version of the zone (stage area), and then display has not changed is stored in temporary storage area (stage area), so you can use to view those files have not been the staging.
  • Diff --cached git : Available --staged in place (after 1.6.1 to git) difference compared to the staging area (stage) and the last submission (commit); usually executed before the commit, to confirm the contents of the file about to commit and changes.

Commit changes

  • Git Commit: will call out the set in the config core.editor text editor to write the contents of the commit comment of.
  •  Git Commit -m: marked with the contents of the second commit comment directly on the command.
$ git commit -m "for repository initial"
  • Git Commit -a: t all be automatically tracked and modified files to the staging area and begin submitting process, allowing users to skip steps git add. (However, the new document does not automatically join scratch, still have to execute git add).

Delete Files

Git -rm $ fileName: remove files from the directory, change and delete records in this staging area

Rm $ fileName: pure crushed remove files from the directory, Git will find the file disappear; but this deletion is not recognized to the staging area.

Renaming Files

$ Git mv file_from file_to: rename the file and execute recognized directly to the staging area.

$ git mv README.txt README

Git -mv This command is equivalent to the following three lines

$ mv README.txt README

$ git rm README.txt

$ git add README

Reference:

https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository

: Original Big column  on [Git] notes Ch2


Guess you like

Origin www.cnblogs.com/chinatrump/p/11516436.html