Linux git安装与部署

目录

git安装

1、下载与安装

2、配置git账号信息

创建本地仓库

1、创建本地代码库文件夹

2、创建项目代码本地仓库文件夹

3、进入到projCode目录下,创建git本地仓库

4、创建过滤文件.gitignore

5、添加.gitignore到git暂存区

6、提交.gitignore

7、将项目代码移动到projCode目录下

8、将项目代码添加git暂存区

9、提交项目代码到仓库中

git本地仓库操作常用命令

查看哪些文件做了修改(与版本做对比)

查看变更摘要

查看某文件变更内容

回退某文件的所有变更

将文件添加到git暂存区

[文件添加到git暂存区后,想将其从暂存区中移出(撤销git add操作)](#文件添加到git暂存区后,想将其从暂存区中移出(撤销git add操作))

提交到版本库

取消某文件的版本追踪

查看仓库的提交日志

查看某项提交详情

查看某文件的提交日志

[Qt Creator中使用git](#Qt Creator中使用git)

1、启用git插件

2、使用git插件操作本地仓库(支持git部分功能)


git安装

1、下载与安装
bash 复制代码
sudo apt install git
2、配置git账号信息
bash 复制代码
#设置邮箱
git config --global user.email "xxx@xxmail.com"
#设置用户名
git config --global user.name "yourName"

创建本地仓库

1、创建本地代码库文件夹
bash 复制代码
mkdir repos
2、创建项目代码本地仓库文件夹
bash 复制代码
mkdir projCode
3、进入到projCode目录下,创建git本地仓库
bash 复制代码
git init
4、创建过滤文件.gitignore

.gitignore内容可参考如下:

bash 复制代码
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

*.stackdump

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
#x64/
#x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
## TODO: Comment the next line if you want to checkin your
## web deploy settings but do note that will include unencrypted
## passwords
#*.pubxml

*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

docs/
data/
src/Config.ini
#*.db
*.opendb
#*.ini
Makefile.Debug
Makefile.Release
Makefile
build_log.txt
5、添加.gitignore到git暂存区
bash 复制代码
git add .gitignore
6、提交.gitignore
bash 复制代码
git commit -m  "上传过滤文件.gitignore"
7、将项目代码移动到projCode目录下
bash 复制代码
命令:mv 原目录 新目录

#文件结构如下:
$ tree ./repos -a  -L  2
./repos
└── projCode
    ├── testProject
    ├── .git
    └── .gitignore

3 directories, 1 file
8、将项目代码添加git暂存区
bash 复制代码
git add .
9、提交项目代码到仓库中
bash 复制代码
git commit -m "提交项目代码"

git本地仓库操作常用命令

查看哪些文件做了修改(与版本做对比)
bash 复制代码
git status
查看变更摘要
bash 复制代码
#显示未添加到暂存区的变更摘要
git diff --stat
#显示已添加到暂存区的变更摘要
git diff --cached  --stat
查看某文件变更内容
bash 复制代码
#查看未添加到暂存区的变更
git diff <文件名>
#查看已添加到暂存区的变更
git diff --cached <文件名>
#查看与上个版本的差异(无论是否添加到暂存区)
git diff <分支名> <文件名>
回退某文件的所有变更
bash 复制代码
git checkout <文件>
#例如:
git checkout -- build-test.sh

#注意:对于已经添加到暂存区的文件,需要先移出暂存区后再进行checkout回退
将文件添加到git暂存区
bash 复制代码
git add <文件或文件夹>
#例如:git add build-test.sh
文件添加到git暂存区后,想将其从暂存区中移出(撤销git add操作)
bash 复制代码
git reset <分支名> <文件名>
#例如: git reset HEAD build-test.sh
提交到版本库
bash 复制代码
git commit <文件名或为空> -m "提交描述信息"
#例如:
git commit build-test.sh -m "提交build-test.sh,无需git add也能提交"
git commit -m "提交暂存区的所有文件"   
git commit -a -m "提交所有变更文件"
取消某文件的版本追踪
bash 复制代码
git rm --cached <文件或文件夹>
#例如:
git rm -r --cached "Makefile"
git rm -r --cached "_qt-Debug/"
#注意:最后执行git commit此操作
查看仓库的提交日志
bash 复制代码
git log
查看某项提交详情
bash 复制代码
git show <提交节点ID>
#例如: git show 56a43568985db6b6d813c64d3p184e7cfb41fofb
查看某文件的提交日志
bash 复制代码
git log -p <文件>

Qt Creator中使用git

1、启用git插件
2、使用git插件操作本地仓库(支持git部分功能)
  • 支持版本差异对比
  • 支持日志查询
  • 支持提交操作
相关推荐
为祖国添砖爪哇15 分钟前
【Git原理与使用】多人协作与开发模型(2)
git
王哲晓27 分钟前
Linux通过yum安装Docker
java·linux·docker
memories19834 分钟前
git使用方法详解(适合新手)
git
gopher951140 分钟前
linux驱动开发-中断子系统
linux·运维·驱动开发
码哝小鱼1 小时前
firewalld封禁IP或IP段
linux·网络
鼠鼠龙年发大财1 小时前
【x**3专享】安装SSH、XFTP、XShell、ARM Linux
linux·arm开发·ssh
nfgo1 小时前
快速体验Linux发行版:DistroSea详解与操作指南
linux·ubuntu·centos
为祖国添砖爪哇1 小时前
【Git原理与使用】版本管理与分支管理(1)
git
Rookie_explorers2 小时前
Linux下go环境安装、环境配置并执行第一个go程序
linux·运维·golang
weixin_424215842 小时前
shell运算实战案例-KFC点餐系统
linux·centos