git学习

一、git的安装

下载window git

Msysgit https://git-scm.com/download/win

二、配置用户信息

git config --global user.name 'zhoudawei'

git config --global user.email '123456789@qq.com'

查看是否配置成功 git config --list

三、初始化版本库

git init

四、添加文件到版本库

git add

git commit

五、查看仓库状态

git status

 sourcetree

pwd 查看当前目录

ll

cd ..

ls -a 显示隐藏和所有文件

echo "git repo2" >> test.txt

cat test.txt

git add test.txt

git commit -m 'repo2 first commit'

git status

git reset HEAD bash_demo.txt

git checkout -- bash_demo.txt

git log

git reset --hard 版本

git rm bash_demo.txt

六、创建SSH key

ssh-keygen -t rsa  -C 'youremail@example.com'

ssh-keygen -t rsa -b 4096 -C 'youremail@example.com'

cd ~

pwd

cd .ssh/

cat id_rsa.pub

测试是否联通   ssh -T git@github.com

开启代理

eval "$(ssh-agent -s)"

.ssh

ls

七、添加远程仓库

git remote add origin git@github.com:zhoudaweidemo/demo.git

git pull origin master --allow-unrelated-histories

git push -u origin master

vim README.md

八、克隆远程仓库 

git clone ‘sdfdsgfdg.gti’

九、标签管理

查看所有标签  git tag

创建标签  git tag name

指定提交信息 git tag -a name -m "comment"

删除标签 git tag -d name

标签发布 git push origin name

十、分支管理

git branch [name]

查看所有分支 git branch

切换分支 git checkout branch

先切换到master分支  git checkout master

git merge  [name]

删除分支  git branch -d [name]

 十一、实践

打开码云,在【分支】选项中选择,并点击【新建分支】按钮,输入新分支名称"index-swiper",点击【创建分支】,在table中就会创建分支名为index-swiper的分支

git pull

git checkout index-swiper

git status

git add .

git commit -m 'add index-swiper'

git push

git checkout master

git merge index-swiper

git push

强制用远端的代码覆盖本地的

git fetch --all && git reset --hard origin/master && git pull

git 错误error: failed to push some refs to

1、先拉下来,会自动合并的(不用操心)

git pull origin master

2、再上传

git push -u origin master

Git强制将本地dist分支覆盖远程的master分支

 git push origin dist:master -f

git checkout -b feature_zdd
git push orgin feature_zdd 
回退命令:

$ git reset --hard HEAD^ 回退到上个版本
$ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前 $ git reset --hard commit_id 退到/进到 指定commit的sha码


强推到远程:
$ git push origin HEAD --force
Git global setup
git config --global user.name "XXX"
git config --global user.email "XXXXXXXX@qq.com"
Create a new repository
git clone http://gitlab.XXX.cn:8088/XXX/XXX.git
cd XXXX
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin http://gitlab.XXXX.cn:8088/XXXX/XXXXX.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote add origin http://gitlab.XXXX.cn:8088/XXXX/XXXXXX.git
git push -u origin --all
git push -u origin --tags
原文地址:https://www.cnblogs.com/zhoudawei/p/10503022.html