git基本配置
- 设置用户信息:
git config --global user.name "your username" git config --global user.email "your_email@domain.com"
设置完成后可查看配置信息: more /root/.gitconfig
- 添加SSH Keys
cd ~ ssh-keygen -t rsa -C "your_email@domain.com" ll ~/.ssh more ~/.ssh/id_rsa.pub
前两句为创建公钥和私钥,输入自己邮箱,连续按三个回车即可 倒数第二句是查看私钥和公钥,第一个文件是私钥,第二个文件是公钥。 最后一句是查看公钥
git基本操作
-
添加文件: git add [文件名/文件夹名]
-
添加全部文件: git add .
-
删除文件: git rm [文件名/文件夹名]
-
删除全部文件:git rm -r –cached .
git建立分支管理
-
建立初始空仓库:git init
-
添加远端仓库:git remote add origin URL
-
解绑远端仓库:git remote remove origin
-
建立本地分支: git checkout -b [分支名]
-
推到远端对应分支(如没有则自动建立): git push origin [本地分支名]:[远端分支名]
-
删除本地分支:git branch -D [本地分支名]
-
查看本地分支:git branch
-
查看远端分支:git branch -r
-
查看全部分支:git branch -a
-
查看本地分支详情:git branch -v
-
查看全部分支详情:git branch -av
-
如果本地仓库和远端仓库初始文件不同,先从远端更新仓库: git pull origin master –allow-unrelated-histories
git实用操作
-
merge工具: git mergetool
-
查看提交日志: git log
-
查看所有操作日志: git reflog
-
根据日志提交的版本号,回退到制定版本: git reset –hard 版本号