天天看点

Git常用命令集Git常用命令集(centos7)

Git常用命令集(centos7)

  • 用户信息配置
git config --global user.name "John Doe"
git config --global user.email "[email protected]"           

这些用户信息存储在home/user下面,是个隐藏文件,需要用命令

ls -a           

才能看到,是./gitconfig文件,在这里可以看到上面--global的配置数据。

  • 配置文本编辑器
git config --global core.editor emacs           
  • 检查配置信息
git config --list //列出所有项目
git config user.name //列出特定项目           
  • 命令手册
git help config           
  • 初始化仓库
git init //进入需要进行版本项目的文件夹再运行命令           
  • 将文件添加到版本控制中或暂存已修改的文件
git add filename           
  • 克隆库,先进入对应的文件夹
git clone https://github.com/notepad-plus-plus/notepad-plus-plus.git           
  • 检查当前文件系统状态
git status           
  • 忽略的文件记录在.gitignore文件中,是一个隐藏文件。
    • 所有空行和已#开头的行都会被忽略。
    • 匹配模式以(/)开头防止递归。
    • 匹配模式以(/)结尾指定目录。
  • 查看文件所修改的地方
git diff           
  • 查看已暂存的将要添加到下次提交里内容
git diff --staged           
  • 提交
git commit
git commit -m "redpig:mark my words"//提交信息放在命令行
git commit -a//跳过缓冲区直接提交           
  • 移除文件
git rm
git rm -f filename//从缓冲区强制删除,同时删除文件
git rm --cached filename//从缓冲区删除,不删除文件           
  • 移动文件
git mv filename1 filename2           
  • 查看提交历史
git log           
  • 生成key,对于不同的repository存储不同的key。在键入生成的key文件时,修改文件名称,比如这里添加了_github后缀,就表示这个key是用于github,以后在同样的位置可以生成key而不覆盖之前生成的key。
ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/test/.ssh/id_rsa): /c/Users/test/.ssh/id_rsa_github
Created directory '/c/Users/test/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/test/.ssh/id_rsa_github.
Your public key has been saved in /c/Users/test/.ssh/id_rsa_github.pub.           

继续阅读