字节跳动Tiktok团队北上广深杭急招前后端开发,绿色内推邮箱:sunmaoyu@bytedance.com

git基础

一. 撤销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)

 

posted @   冒雨ing  阅读(247)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示