git学习笔记

git学习
一,安装配置和基本命令

1,官网下载git
2,安装git
3,配置git账户和邮箱
git config --global 一次性设置(基本不用)
git config --system system 给当前用户设置
git config --local 当前项目设置

git config --local user.name “xxxx”
git config --local user.email “xxx@qq.com”

查看配置的用户名和邮箱
C:\Users\Administrator.gitconfig

配置别名
git config --global alias.st status st表示status的别名
删除用户
命令
git config --global --unset user.name
git config --global --unset user.email
同理,删当前用户或者当前项目的用户如下命令
git config --local --unset user.name
git config --system --unset user.name
或者删除.gitconfig文件
C:\Users\Administrator.gitconfig
4,克隆或拉代码
git clone https://github.com/xxxxx/springcloud-config.git
5,删除暂存区文件和撤销删除
git rm hello.txt
撤销工作区
git checkout --hello.txt
撤销暂存区,有2步
1,将暂存区恢复到工作区
git reset HEAD hello.txt
2,git checkout --hello.txt
6,新建文件 touch 1.txt
7,添加 git add 1.txt
8,提交到暂存区 git commit -m ‘1.txt’
9,提交到github,需要输入github用户名和密码
git push -u origin master
或将本地仓库和远程仓库关联
git remote add origin 远程仓库地址
10,重命名,先命名成2.txt再提交到暂存区,再提交到远程(第一次push需要用git push -u origin master)
git mv 1.txt 2.txt
git commit -m “2.txt”
git push
11,将上次注释重命名
git commit -m ‘2.txt’ ‘rename’
git commit --amend -m ‘上次注释重命名’
git push 推到远程仓库
先add在commit
git commit -am ‘second’
12,.gitignore 忽略提交文件
touch .gitignore
.class忽略所有class文件
!a.properties不包含a.properties
libin/
.md忽略所有libin目录下的md文件

git tag v1.0 给当前分支打标签为v1.0
git tag 查看当前仓库的标签列表
git tag v2.0 commitid 给指定版本打标签
git tag v1.1 -m ‘给标签加说明’
git tag -d v1.0 删除标签

二,分支

查看分支 git branch
创建分支 git branch newbranch
切换分支 git checkout newbranch
删除分支 git branch -d newbranch (注意不能删除当前分支,-D强制删除)
创建并切换分支 git checkout -b newbranch

git branch -v 查看最近的分支
git log 查看日志(git log --pretty=oneline)
fast forward:如果一个分支靠前(dev),另一个分支靠后,如果不冲突,master可用通过merge直接赶上dev
1,默认开启,也可以禁止,git merge --no-ff
2,fast forward分支信息完整(不丢失分支信息)

三,版本穿梭

回退到上一次commit:git reset --hard HEA(表示回退几步)
回退到指定版本 git reset --hard 版本号(commitid,可以根据git log查看commitid)

拉取指定版本 git checkout 版本号
修改后必须提交,提交后对后面的分支不影响,只对修改的当前历史版本有效,没意义
再创建一个分支 git branch 分支名 历史版本号

四,.gitignore文件模板
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template

# IntelliJ project files
*.idea
*.iml
out
gen
#eclipse
.project
.classpath
.settings
### Java template
# Compiled class file
*.class
target

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.gitignore
mycode.iml



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值