git仓库操作方法管理

1、初始化生成公钥

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

2、配置用户名邮箱

当前仓库配置:

git config user.name "Your Name"
git config user.email "email@example.com"

全局配置:

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

3、查看配置信息

查看系统config
git config --system --list

查看当前用户(global)配置
git config --global --list

查看当前仓库配置信息
git config --local --list

4、添加远程仓库

文件夹存在的时候,新建仓库并添加远程仓库:

cd existing_folder
git init
git remote add origin git@xxx.xxx.xxx.xxx:Project/service.git
git add .
git commit
git push -u origin master

仓库存在的时候,添加远程仓库:

cd existing_repo
git remote add origin git@xxx.xxx.xxx.xxx:Project/service.git
git push -u origin --all
git push -u origin --tags

5、修改提交模板git_template

git config commit.template [模板文件名]    //这个命令只能设置当前分支的提交模板
git config commit.template git_template 

git config --global commit.template [模板文件名]    //这个命令能设置全局的提交模板,注意global前面是两杠 
git config --global commit.template git_template

6、no matching key exchange method found算法不匹配提示解决方案

问题提示:

Unable to negotiate with 192.168.4.28 port 19428: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.

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

解决方案:

  • 1、修改ssh config文件

windows:

cd ~/.ssh/
vim config

linux:

/etc/ssh/ssh_config
vim ssh_config
  • 2、修改config文件内容,如下:
Host *.*.*.*  
    KexAlgorithms +diffie-hellman-group1-sha1
  • 3、再次执行 git clone xxx.git,即可执行成功。

---------------------------------------------------分割线------------------------------------------------------

7、gerrit change-id第一次提交时不成功的解决办法

  • 1、根据提示:复制提示中的gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@xxx.xxx.xxx.xxx:hooks/commit-msg ${gitdir}/hooks/到命令行,并点击回车执行。
  • 2、执行git commit --amend命令,重新commit提交代码
  • 3、执行git push命令,上传代码到服务器即可
>gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@xxx.xxx.xxx.xxx:hooks/commit-msg ${gitdir}/hooks/
>git commit --amend
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。