Linux git安装与部署

Jane_Yih 2024-10-03 15:37:05 阅读 81

目录

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操作)

提交到版本库

取消某文件的版本追踪

 查看仓库的提交日志

 查看某项提交详情

 查看某文件的提交日志

Qt Creator中使用git

1、启用git插件

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


git安装

1、下载与安装

<code>sudo apt install git

2、配置git账号信息

#设置邮箱

git config --global user.email "xxx@xxmail.com"

#设置用户名

git config --global user.name "yourName"

创建本地仓库

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

mkdir repos

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

mkdir projCode

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

git init

4、创建过滤文件.gitignore

.gitignore内容可参考如下:

## 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暂存区

git add .gitignore

6、提交.gitignore

git commit -m "上传过滤文件.gitignore"

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

命令:mv 原目录 新目录

#文件结构如下:

$ tree ./repos -a -L 2

./repos

└── projCode

├── testProject

├── .git

└── .gitignore

3 directories, 1 file

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

git add .

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

git commit -m "提交项目代码"

git本地仓库操作常用命令

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

git status

查看变更摘要

#显示未添加到暂存区的变更摘要

git diff --stat

#显示已添加到暂存区的变更摘要

git diff --cached --stat

查看某文件变更内容

#查看未添加到暂存区的变更

git diff <文件名>

#查看已添加到暂存区的变更

git diff --cached <文件名>

#查看与上个版本的差异(无论是否添加到暂存区)

git diff <分支名> <文件名>

回退某文件的所有变更

git checkout <文件>

#例如:

git checkout -- build-test.sh

#注意:对于已经添加到暂存区的文件,需要先移出暂存区后再进行checkout回退

将文件添加到git暂存区

git add <文件或文件夹>

#例如:git add build-test.sh

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

git reset <分支名> <文件名>

#例如: git reset HEAD build-test.sh

提交到版本库

git commit <文件名或为空> -m "提交描述信息"

#例如:

git commit build-test.sh -m "提交build-test.sh,无需git add也能提交"

git commit -m "提交暂存区的所有文件"

git commit -a -m "提交所有变更文件"

取消某文件的版本追踪

git rm --cached <文件或文件夹>

#例如:

git rm -r --cached "Makefile"

git rm -r --cached "_qt-Debug/"

#注意:最后执行git commit此操作

 查看仓库的提交日志

git log

 查看某项提交详情

git show <提交节点ID>

#例如: git show 56a43568985db6b6d813c64d3p184e7cfb41fofb

 查看某文件的提交日志

git log -p <文件>

Qt Creator中使用git

1、启用git插件

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

支持版本差异对比支持日志查询支持提交操作



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。