本文目录
欢迎来到Stephen的博客。我是小达,一名普通的在校大学生。希望大家多多关照,我们一起成长一起进步,也希望大家多多支持我鸭,喜欢我就给我一个关注吧!
一、问题引导(比较svn和git的优缺点)
代码经常修改,需不需要记录每次版本的差异?
多人合作开发的话,需不需要去同步每个人更改的代码?
二、安装git
要使用gitee
,需要先安装git
工具。
git
工具下载:https://git-scm.com/downloads
安装完成后,在命令行输入git --version
可以查看到git
的版本。
右键菜单也会出现相应的菜单。
三、登录gitee
我们先在 gitee
上注册账号并登录。
gitee
官网:https://gitee.com/
四、创建一个项目
点击右上角的 +
号,新建仓库
如下,填写仓库信息,最后点击创建即可。 注意:公开须知提交前需要全打勾!
五、克隆仓库到本地
点击克隆/下载
,然后点击HTTPS
,复制git
链接
接着,在本地目录空白处右键菜单,点击Git Bash Here
。
输入git clone 刚刚的git链接
,如下
git clone https://gitee.com/JD30/StudyNotes.git
成功后,本地目录即可看到克隆下来的README
文件。
六、关联本地工程到远程仓库
有时候,我们可能是先在本地有了工程文件,然后再在gitee
上创建仓库的。
此时,可在本地库上使用命令 git remote add
把它和 gitee
的远程库关联,如下
git remote add origin https://gitee.com/JD30/StudyNotes.git
如果在使用命令 git remote add
时报错:
git remote add origin https://gitee.com/JD30/StudyNotes.git
fatal: remote origin already exists.
说明本地库已经关联了一个名叫 origin
的远程库,此时,可以先用git remote -v
查看远程库信息:
git remote -v
origin https://gitee.com/JD30/StudyNotes.git (fetch)
origin https://gitee.com/JD30/StudyNotes.git (push)
我们可以删除已有的远程库
git remote rm origin
再关联远程库
git remote add origin https://gitee.com/JD30/StudyNotes.git
七、基本使用(交作业版)
git的基本使用(以下命令需要在git仓库文件夹下面操作)
1、git init初始化仓库,把一个普通文件夹变成git仓库,使用git命令去管理。(同目录下多出一个.git文件夹)
2、git add文件名/ git add --all添加文件到追踪暂存区
3、git status查看当前git仓库的修改文件的状态,哪些修改文件追踪了,哪些没有被追踪
4、git commit -m "xxxx”提交本次修改到历史版本记录。xxxx是对这次提交的说明
5、git log 查看历史版本记录git log -p 是查看详细提交代码
6、git reset 08f4beb4beab0fdd138914b66aaac71bae657e67 --hard回滚到指定版本08f4be..是版本号
7、git reflog 记录每次提交的版本号
8、git remote add origin xxx添加别名映射,将远程仓库地址xxx映射为origin
9、git remote -v查看当前有哪些别名映射
10、git remote delete origin删除origin别名映射
11、git pull origin master拉取远程origin仓库的内容到本地仓库
12、git push origin master推送本地仓库的历史修改到远程仓库
八、添加文件
在本地添加文件,如下,添加一个AddFileTest.txt
文件。
九、执行git命令,提交文件
打开git
,执行git
的add
、commit
、push
命令,即可将本地文件上传到远程仓库。
注:常用的git
命令见文章最后面。
刷新gitee
页面,即可看到本地文件已经上传到```gitee``上了
十、删除仓库
点击管理
点击删除仓库,根据提示输入密码即可
十一、常用的git命令
常用的git
命令
git init #把当前目录变成git可以管理的仓库
git clone git地址 #克隆项目
git add readme.txt #添加一个文件,也可以添加文件夹
git add -A #添加全部文件
git rm test.txt #删除一个文件,也可以删除文件夹
git commit -a -m “some commit” #提交修改
git status #查看是否还有未提交
git log #查看最近日志
git reset --hard HEAD^ #版本回退一个版本
git reset --hard HEAD^^ #版本回退两个版本
git reset --hard HEAD~100 #版本回退多个版本
git remote add origin +地址 #远程仓库的提交(第一次链接)
git push -u origin master #仓库关联
git push #远程仓库的提交(第二次及之后)
git fetch #从远程获取代码库
git tag xxx #打tag
git tag #显示所有tag
git push --tag #提交tag
git branch -a #显示所有分支
git checkout 分支名 #切换分支
git merge git分支 #合并分支
更多的git
命令,可以输入git --help
查看,或者访问git
命令手册:https://git-scm.com/docs
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.