Directorio artículo
- En primer lugar, ¿qué es Git
- En segundo lugar, las razones de instalar y de control de versiones Git
- En tercer lugar, la gestión de archivos Git
- Cuatro, tres regiones de Git
- En quinto lugar, la reversión de versión y recuperación de archivos
En primer lugar, ¿qué es Git
1.Git definido
Git es distribuido el control de versiones de software .
- Software
como QQ, oficina y otras herramientas instalado en su ordenador u otro dispositivo electrónico para su uso. - El control de versiones
es la tesis similares, copia de la escritura, clips de vídeo, etc., necesidad de modificar y mantener los datos históricos originales en varias ocasiones . - repartido
2. El desarrollo de control de versiones distribuido
Archivo (carpeta) copia
Basta con copiar el primer momento, y luego modificado a partir de la copia, Guardar todas las versiones, no sólo va a ocupar una gran cantidad de memoria, y difícil de manejar y sincronizar compartido con otros, de la siguiente manera:
Control de versiones locales
Sólo más tarde se convirtió en un archivo, guardar múltiples versiones del archivo en el software, pero aún no es propicio para el intercambio entre los diferentes desarrolladores de sincronización, de la siguiente manera:
control de versiones centralizado
Un mayor desarrollo, a un control de versiones centralizado, como SVN, hay un centro de control de guardar todas las versiones, pero debido a la falta de la versión local, como el problema central, la versión no se realice completamente locales, todo el proyecto se puede perder o no puede ser normal, de la siguiente manera:
Control Distribuido Version
Ahora y luego distribuido de control de versiones como Git, la versión se presentará a nivel local, y luego sincroniza con el centro, así como para mejorar la tolerancia a fallos, como sigue:
En segundo lugar, las razones de instalar y de control de versiones Git
1. El control de versiones razón
Para preservar todas las versiones anteriores, a fin de hacer retroceder y modificar.
Por las siguientes razones:
- Escrito proceso de procedimientos específico es un proceso iterativo procesos de edición tomado la molestia de editar, modificar cuando no se quiere destruir el estado antes de la modificación, lo mejor es modificar el período de cada caso, será capaz de guardar un estado, como una instantánea de un sistema automático similares, cuando detrás algo va mal, puede elegir un estado de instantáneas antes de la recuperación;
- Por último, cuando la liberación de software a menudo tienen múltiples versiones del software de código fuente generado es a menudo sólo uno, pero cuando se utiliza en diferentes partes de la última compilación, la mayor parte del código es compartido, por lo que a menudo se requiere el control de versiones varias versiones copiar unas cuantas carpetas a cabo;
- Con el control de versiones, puede navegar por toda la historia del desarrollo, sujete el progreso del equipo de desarrollo, y cualquier cambio ya no tienen miedo, porque se puede recuperar fácilmente antes de volver a la versión normal, la función también se puede hacer a través de ramas y etiquetas diferentes versiones de la versión de software.
El desarrollo es siempre un proceso, en lugar de los resultados. El control de versiones es el proceso de seguimiento del proceso de grabación, los logros alcanzados en el proceso.
2. Instalar Git
Es necesario descargar el archivo de instalación, puede hacer clic https://git-scm.com/download elegir el sistema correcto y la versión de descarga, si la velocidad de descarga es demasiado lento puede ser descargado a través del espejo.
También puede hacer clic directamente https://download.csdn.net/download/CUFEECR/12275488 descarga.
Después de descargar clic para instalar, elegir el directorio de instalación y completar la instalación.
Después de que la instalación se haya completado, el botón derecho del ratón para ver la interfaz gráfica de usuario de Git Aquí y Git Bash Aquí la instalación es correcta.
Todo el proceso de instalación es instalar Git en el local de .
Derecho puede elegir Git Bash Aquí , una ventana de comandos se abrirá, puede introducir git --vsesion
para ver la versión GIT, introduzca git --help
la documentación de ayuda, los ejemplos son los siguientes:
Lenovo@LAPTOP-61GNF3CH MINGW64 ~/Desktop
$ git --version
git version 2.25.0.windows.1
Lenovo@LAPTOP-61GNF3CH MINGW64 ~/Desktop
$ git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
sparse-checkout Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
En tercer lugar, la gestión de archivos Git
- En la carpeta que desea administrar
- elección correcta Git Bash Aquí
- inicialización
git init
- Comprobar el estado de archivo en el directorio
git status
-
gestión de archivos
- archivo especificado gestión
git add xxx
- Toda la gestión de archivos
git add .
-
La información personal (nombre de usuario, correo electrónico) para configurar
la primera operación usando Git. sho
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
- versión generación
git commit -m '描述信息'
- Ver la versión
git log
Las pruebas son las siguientes:
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest
$ git init
Initialized empty Git repository in E:/projecttest/.git/
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
# 创建新文件index.html后
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html # 红色
nothing added to commit but untracked files present (use "git add" to track)
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git add index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html # 绿色
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m 'v1'
# 首次使用会提示配置个人信息
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Lenovo@LAPTOP-61GNF3CH.(none)')
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git config --global user.email "[email protected]"
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git config --global user.name "Corley"
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m 'v1'
[master (root-commit) 1e8ddbf] v1
1 file changed, 15 insertions(+)
create mode 100644 index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
# 创建新文件
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ touch readme.txt
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
nothing added to commit but untracked files present (use "git add" to track)
# 修改index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git add index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m 'v1.1'
[master 5f6b74b] v1.1
1 file changed, 1 insertion(+)
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
nothing added to commit but untracked files present (use "git add" to track)
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit 5f6b74bb67e375a4f9ebc2658893b5eaab2e3bb1 (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 15:58:08 2020 +0800
v1.1
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git add .
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git submit -m 'v1.15'
git: 'submit' is not a git command. See 'git --help'.
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m 'v1.15'
[master 2ec3695] v1.15
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme.txt
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit 2ec36954c41be1836644d2f18d185ca8e1f67c78 (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 16:01:43 2020 +0800
v1.15
commit 5f6b74bb67e375a4f9ebc2658893b5eaab2e3bb1
Author: Corley <[email protected]>
Date: Fri Mar 27 15:58:08 2020 +0800
v1.1
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
nothing to commit, working tree clean
Cuatro, tres regiones de Git
tres regiones de Git incluyen:
- Espacio de trabajo
- Tiene archivo de control
- Los cambios y los nuevos archivos (logotipo rojo)
- área de ensayo (logotipo verde)
- repositorio
Ilustran como sigue:
mejoras de código, agregue una nueva funcionalidad, la prueba:
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git add .
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m 'v2'
[master 742d05c] v2
1 file changed, 6 insertions(+)
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
nothing to commit, working tree clean
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit 742d05cf56bd15331d6c762a2f6f86b56c14a45b (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 16:06:18 2020 +0800
v2
commit 2ec36954c41be1836644d2f18d185ca8e1f67c78
Author: Corley <[email protected]>
Date: Fri Mar 27 16:01:43 2020 +0800
v1.15
commit 5f6b74bb67e375a4f9ebc2658893b5eaab2e3bb1
Author: Corley <[email protected]>
Date: Fri Mar 27 15:58:08 2020 +0800
v1.1
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git add .
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git git commit -m '-v3'
git: 'git' is not a git command. See 'git --help'.
The most similar command is
init
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git commit -m '-v3'
[master f12719f] -v3
1 file changed, 6 insertions(+)
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit f12719f22469243dd4e95bc3de7da2f524627938 (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 16:17:09 2020 +0800
-v3
commit 742d05cf56bd15331d6c762a2f6f86b56c14a45b
Author: Corley <[email protected]>
Date: Fri Mar 27 16:06:18 2020 +0800
v2
commit 2ec36954c41be1836644d2f18d185ca8e1f67c78
Author: Corley <[email protected]>
Date: Fri Mar 27 16:01:43 2020 +0800
v1.15
commit 5f6b74bb67e375a4f9ebc2658893b5eaab2e3bb1
Author: Corley <[email protected]>
Date: Fri Mar 27 15:58:08 2020 +0800
v1.1
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
...skipping...
commit 742d05cf56bd15331d6c762a2f6f86b56c14a45b
Author: Corley <[email protected]>
Date: Fri Mar 27 16:06:18 2020 +0800
En quinto lugar, la reversión de versión y recuperación de archivos
1. Rollback
- volver rollo a la versión anterior
git log
git reset --hard 版本号
- Después de la vuelta a la versión rollo
git reflog
git reset --hard 版本号
Donde log
comando para ver la versión antes de la reversión, reflog
comprobar la versión después de la reversión.
Deshacer prueba hacia adelante:
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git reset --hard 742d05cf56bd15331d6c762a2f6f86b56c14a45b
HEAD is now at 742d05c v2
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git log
commit 742d05cf56bd15331d6c762a2f6f86b56c14a45b (HEAD -> master)
Author: Corley <[email protected]>
Date: Fri Mar 27 16:06:18 2020 +0800
v2
commit 2ec36954c41be1836644d2f18d185ca8e1f67c78
Author: Corley <[email protected]>
Date: Fri Mar 27 16:01:43 2020 +0800
v1.15
commit 5f6b74bb67e375a4f9ebc2658893b5eaab2e3bb1
Author: Corley <[email protected]>
Date: Fri Mar 27 15:58:08 2020 +0800
v1.1
commit 1e8ddbf90b34a2c11374813cd6d154d73283428e
Author: Corley <[email protected]>
Date: Fri Mar 27 15:51:36 2020 +0800
v1
En este momento se encuentra la parte trasera código para el tiempo de la versión V2.
Deshacer siguiente prueba:
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git reflog
742d05c (HEAD -> master) HEAD@{0}: reset: moving to 742d05cf56bd15331d6c762a2f6f86b56c14a45b
f12719f HEAD@{1}: commit: -v3
742d05c (HEAD -> master) HEAD@{2}: commit: v2
2ec3695 HEAD@{3}: commit: v1.15
5f6b74b HEAD@{4}: commit: v1.1
1e8ddbf HEAD@{5}: commit (initial): v1
Lenovo@LAPTOP-61GNF3CH MINGW64 /e/projecttest (master)
$ git reset --hard f12719f
HEAD is now at f12719f -v3
2. Recuperación de archivos
- La recuperación de archivos modificados
git checkout -- xxx
- Volver al espacio de trabajo desde cero
, incluso si el nombre de archivo del color de verde a rojo
git reset HEAD xxx
Ejemplo de ensayo: