Git up a local repository and its use

GIT

1. What is git?
Git is the world's most advanced distributed version control system. Effective, high speed process from very small to very large project version management. Git is Linus Torvalds To help manage Linux kernel development and the development of an open source version control software. Torvalds began developing Git is intended as an interim solution to replace BitK

2.git and svn difference of
fact, in our daily study or work and we also used a similar git repository, such as svn, then we talk about the difference between the two sections of

  • SVN is centralized version control system, the repository is focused on the central server, and work time, are used in their computers, so first of all from a central server where to get the latest version, and then to work, finish , we need to finish the job on their own to a central server. Centralized version control system must be networked to work, if it can, the bandwidth is large enough in LAN, fast enough, if in the Internet, if Suman, then wonder.
  • Git is a distributed version control system, then it has no central server, each person's computer is a complete repository, so that when things do not need to work, because the versions are on your own computer. Since everyone's computer has a complete repository, how much how individuals collaborate it? For example, to change their own files on the computer A, the others are changed A file on the computer, then, you just need to give each other their own changes pushed between the two, we can see each other's changed.
    Compared to the centralized distributed biggest difference is that the developer can be made locally by each developer cloning (git clone), a complete copy of the local machine Git repository

3. What is the version control system:

  • Version control is a record of one or several file content changes, for future reference system-specific version of the revision

4. What is a distributed version control system:

  • Distributed version control systems (Distributed Version Control System, referred to as the DVCS), in such systems, like Git, Mercurial, Bazaar and Darcs other clients do not just check the latest version of the snapshot file, but the code is fully mirror the repository down. This way, any one server fails to work with, and afterwards can use any of a mirror out of the local repository recovery. Because every clone operation, is really a full backup of all the data.

Features of 5.git

  1. Clones from the server database (including the code and version information) to the single
  2. Create a branch, modify the code on their own machines
  3. Submit code on a branch on a single machine that you create
  4. Merging branches on a single machine
  5. Create a new branch, the latest version of the server code fetch down, and then merged with their main branch
  6. Generate patch (patch), to send their patches to the main developer
  7. See the main developer feedback, if developers find the main conflict (we can work together to resolve the conflict between them) between two general developer, will require them to resolve the conflict, and then submitted by one person. If the primary developers themselves, or there is no conflict, just by
  8. The solution of the conflict between the general developers submit patches again after the main developers can use between the developers pull command to resolve the conflict, complete resolution of conflicts

Build and use a local Git repository

1. Install git

[root@server1 ~]# yum install -y git

2. Create our local warehouse, and initialization

[root@server1 ~]# mkdir demo	#这里创建的版本库的名字为demo
[root@server1 ~]# cd demo/
[root@server1 demo]# ls -a
.  ..
[root@server1 demo]# git init	#进行初始化,需要在版本库目录中(这里的版本库目录为demo
Initialized empty Git repository in /root/demo/.git/
[root@server1 demo]# l.
.  ..  .git
[root@server1 demo]# ls .git/
branches  config  description  HEAD  hooks  info  objects  refs

The current directory can be found more than a .git directory, and this directory is to manage Git repository, generally do not manually modify the .git directory inside the file.
3. Add user information
initialization finished, the next step is to set a user name and e-mail addresses, each Git submit this information will be included with the fact that information can be said label owner of the warehouse, it can be said contact information

[root@server1 demo]# git config --global user.name ljz
[root@server1 demo]# git config --global user.email ljz.redhat.com

Check the user name and mailbox
Here Insert Picture Description
4. Driven files, view file status repository

[root@server1 demo]# touch file1
[root@server1 demo]# echo redhat > file1 
[root@server1 demo]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	file1
nothing added to commit but untracked files present (use "git add" to track)
[root@server1 demo]# git status -s
?? file1		##新添加的未跟踪的文件前面有??标志

5. Add the file, the file is placed in the staging area

[root@server1 demo]# git add file1
[root@server1 demo]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   file1
#
[root@server1 demo]# git status -s
A  file1		 ##A表示已经添加到暂存区了

6. Submission of change, in fact, is to submit all the contents of the staging area to the current branch

[root@server1 demo]# git commit -m "add file1"
[master (root-commit) 6be0829] add file1
 1 file changed, 1 insertion(+)
 create mode 100644 file1
[root@server1 demo]# git status -s	提交完后我们就会发现状态栏就没有文件了

7.git status classification status display

  • Untracked added file comes in before the tag,
  • Newly added to the staging area in front of the file has marked A,
  • Modified file has the M flag in front.
  • M appears on the right indicates that the file has been modified but not yet put into temporary storage area,
  • It appears to the left by the M indicates that the file has been modified and placed in a temporary storage area.
  • MM is the work area has been modified and submitted to the staging area later was modified in the workspace, so in the staging area and workspace has the file has been modified record
    Here Insert Picture Description

8. Ignore files
generally do not need to incorporate some of the documents we always manage Git, they always do not want to appear in the list of untracked files. These are generally automatically generated files such as log files or temporary files created during compilation. In this case, we can create a file named .gitignore, listing the file mode to ignore.
Here Insert Picture Description
9. version rollback
like this, you continue to make changes to the file, and then continue to commit changes to the repository, Git is the same, whenever you feel file modification to a certain extent, can "save a snapshot" This snapshot is called commit in Git. Once you file a change of chaos, or mistakenly deleted files, you can recover from a recent commit, and then continue to work, rather than the outcome of several months of work lost.
(1) git checkout - file

  • Discard changes to the work area, it is to make the file back to the state at the time of the last git add or git commit

    Here Insert Picture Description
    In fact, these can be found by viewing the status of the corresponding command

(2) git log command displays the commit log from the most recent to the furthest
Here Insert Picture Description
Here Insert Picture Description

(3) git log --pretty = oneline brief view log information
Here Insert Picture Description
(4) git reflog View History
Here Insert Picture Description
(5) git reset --hard HEAD ^

  • A state that is submitted on the HEAD , on the submission of a state is the HEAD ^
    Here Insert Picture Description

(5) git reset --hard ... fall back to a specified state
Here Insert Picture Description

10. Delete recovery

  • After deleting not submitted directly to: git checkout - file can be
    Here Insert Picture Description
  • After deleting and submit: git reset --hard designated state
    Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_42446031/article/details/91874308