1.安装git
sudo apt-get install git-core gitk
2.git设置文件状态颜色
设置编辑器:
git config --global color.editor emacs
设置UI颜色开关:
git config --global color.ui true
颜色状态:
git config --global color.status true
自定义颜色
git config --global color.status.changed "red"
或.gitconfig文件中直接修改这几个参数
3.git查看修改记录
git log p filename 查看文件修改记录
git log --author="username" 根据作者搜索
git log - s "关键字" --文件路径
git log [branch] --grep = DTS单号
git log commitid
git blame 文件全路径 查看文件内容最近一次修改信息
4.常用git命令
克隆中心库到本地
git clone 中心库名称地址 本地工作目录名称
退回上一次提交地址(不保存修改)
git reset --hard HEAD^
退回上一次提交地址(保存修改)
git reset HEAD^
更新代码
git pull (repo sync .)
查看本地是否修改
git status
对比文件修改
git diff
修改文件添加到索引
git add .(.表示全部修改或者单个文件名 多个文件中间用空格隔开)
删除文件添加到索引
git rm 文件名
提交修改到本地库
git commit (手动修改message,保持合和.gitmsg文件一致)
git commit -m " new message changeid(保持上次一致)" --amend(第二次提交修改提交信息)
提交到远程分支
git push origin HEAD:refs/for/远程分支名 (repo upload)
备份修改暂存缓存区
git stash
取出缓存区内容
git stash pop
5.分支:
新建分支
git branch 分支名(repo start 分支名 -all)
切换分支
git checkout 分支名
新建分支并切换该分支
git checkout -b 本地分支名 远程分支名
删除分支
git branch -d或D 分支名 (删除本地分支)
查看分支
git branch (所有本地分支)
git branch -r (所有远程分支)
git branch -a (所有分支)
git status -vv (查单前分支对应远端分支)
6.回退文件状态
回退到修改之前(status查看红色)
git checkout . (所有修改文件及文件夹)
git chekout --文件名 (单个修改文件及文件夹)
rm filename / rm dir -rf(单个新增文件及文件夹)
git clean -xdf(所有新增文件及文件夹)
回退到添加索引前(add了但没commit)
git reset HEAD . (所有修改文件)
git reset HEAD 文件名(单个文件)
回退到提交代码前(commit了但没有push)
git reset commitId (git log查看上一次的id,可以是前6位,commit修改还在)
git reset --hard commitId(清除commit修改,工作区暂存区代码也会清除)
push后回到修改文件
git reset --soft HEAD~
git reset HEAD^
回退冲突文件两步
git reset HEAD 文件名
git checkout 文件名
如果有新增文件
git clean -df
附:
repo简单命令
初始化
repo init ....
同步代码
repo sync -j16
repo sync -c (保留上次同步)
repo sync --force-sync filePath
同步当前仓下代码:
repo sync .
提交到远程分支
repo upload [.]