码迷,mamicode.com
首页 > 其他好文 > 详细

git基础

时间:2018-05-18 18:00:30      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:div   撤销   git基础   命令   改变   public   需要   set   -o   

一. 撤销git add的文件

git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件。

注意 -A 选项后面还有一个句点。 git add -A表示添加所有内容, git add . 表示添加新文件和编辑过的文件不包括删除的文件; git add -u 表示添加编辑或者删除的文件,不包括新添加的文件。

 

技术分享图片

 

 撤销git add 的文件,将暂存区stage中的文件删除:

 git rm -r --cached .

 

 二. 初始化git仓库

Git global setup
git config --global user.name "maoyu"
git config --global user.email "88888888@qq.com"
Create a new repository
git clone git@gitlab.com:guojiang/grab.git
cd grab
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 git@gitlab.com:guojiang/grab.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com:guojiang/grab.git
git push -u origin --all
git push -u origin --tags

 

三. 克隆指定远程分支

git clone -b xxx(分支名) git@gitlab.com:saysmy/test.git

例如:
git clone -b release/test git@gitlab.com:gj-frontend/xingguang.git;

 

 


 

常见问题:

Could not open a connection to your authentication agent

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

如果确定公钥已经放到github或者gitlab等,那么运行下面的命令检查下:

 cat .git/config

是否远程仓库地址不对?

 ssh-add -l

如果提示  Could not open a connection to your authentication agent.  运行  ssh-agent bash , 再执行下面的。

如果提示The agent has no identities.则需要把私钥加到ssh-agent ssesion中:

ssh-add ~/.ssh/gitlab_id_rsa

再运行 ssh-add -l  发现加入成功:

2048 a3:2f:8c:9b:2b:ae:d4:23:9b:c6:47:4e:94:47:38:c2 /root/.ssh/gitlab_id_rsa (RSA)

 

git基础

标签:div   撤销   git基础   命令   改变   public   需要   set   -o   

原文地址:https://www.cnblogs.com/saysmy/p/6702656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!