Git and Github

Git and Github use

This article describes the basic concepts and local Git repository using basic methods.

Version control tools : collaborative modification, data backup, version management, access control, history, branch management.


Basic introduction of Git

  • It is a snapshot of the file system by way of, for each version of the file information management tool, version control tool. SVN incremental management approach is used.

  • Is a distributed version control tools, and SVN is centralized control.

    1, a distributed version control system there is no "central server", each person's computer is a complete repository, without networking security phase for centralized version control systems is much higher.

    2, distributed version control system also has a strong branch management capabilities, allows development teams to more production lines at the same time promote the task in the work process, greatly improving efficiency.

  • For developers outside the team involved in the authority control, review their code.


Git command line operation

1. Set signature

The following codes are input on the command line, is provided for user.name and user.email

git config --global user.name [user.name]

git config --global user.email [user.email]

--global users of the system level, information is stored in :~/.gitconfiga file.

You can $ cat ~/.gitconfigview the command.

2. Create a local library

Choose the right place, create an empty directory and enter (you can not follow the default path).

$mkdir gitwork
$cd gitwork

You can enter pwdto view the current directory displayed

3. warehouse initialization

git init

Successful initialization, the current directory more than a .gitdirectory and can not be modified or deleted.

You can use ls -ahview hidden.git

4. Status View

git status

The current library is empty, so no commits. Branch is master.

5. Add File

1, you want to add a file, you must first write a file. By vim [filename]writing a .txt file, about vim is not too much in this inquiry, as the exit key ESC, and then enter :wqthe file will be created.

2, use git add [filename]the command, the file is added to the staging area.

Can be found, there have been warning statement. Note:
warning: LF by CRLF by Will BE REPLACED in app.wxss.
At The Original File by Will have have the ITS Line Endings in your Working Directory.
The reason is present in the path / symbol escape problems, false symbol is not converted default is true, quite time to escape to the / symbol path, so there is the added problem. the solution is to enter the following command, and then planned to go.
git config --global core.autocrlf false

6. submission

At this point re-enter git statusthe command, you can view the status of the warehouse, to deepen understanding of the work area staging area and local libraries.

A new file is added to the staging area, the green part is displayed. Add the "create, modify," the file to the staging area .

git commit -m "message"[filename]

The contents submitted to the staging area of ​​the local library.

7. History

git log

Of course, here as a demonstration, only one step behavior. In the actual application process, an updated version of the frequency is very high, so in order to clear look at comfort, you can use the following command:

git log --pretty=oneline 包含sha1哈希值,指针指向,以及commit内容
git log --oneline  包含一小部分sha1哈希值,指针指向以及commit内容
git reflog 包含一小部分哈希值,HEAD@{移动到当前版本需要的步数}以及commit内容

8. forward and back

After several revisions submitted an application interface into the following:

  • Back: git reset --hard HEAD^it represents a step back

提示:HEAD is now at f435d69 commit youfirst.txt

git reset --hard HEAD~nN represents a backward step

git reset --hard[index]Based on the index value

  • Forward: only based on the index value, recommended.

Forward or backward, HEAD pointers are updated with the version in the change.


Comparison of the three parameters reset

  • --soft: HEAD pointer to move only in the local library.

  • --mixed: HEAD pointer moves in the local library.

    To reset the staging area.

  • --hard: HEAD pointer moves in the local library.

    To reset the staging area.

    Resetting the workspace.


9. Delete File

前提: Before deleting existing files submitted to the state of the local library.

git reset --hard[指针位置]

  • Delete operation has been submitted to the local library: pointer to point to the location history.
  • Delete operation has not been submitted to the local library: pointer position using HEAD.

10. Comparison of file differences

1、git diff[filename]: The workspace files and staging area for comparison.

2、git diff[本地库中的历史版本][文件名]: Workspace and the local library comparative history records.

3, comparing multiple files without a file name.

Guess you like

Origin www.cnblogs.com/summerday152/p/11790036.html