506629361 发表于 2018-1-15 16:59:23

git 笔记


[*]从本地git仓库中导出工作文件 git checkout
[*]查看历史git log filename
  git log -p #查看每个阶段的具体差异
  git log --stat --summary#查看改变的概述


[*]查看某次提交的文件内容
  git show commit-name:filename #commit-name来源于git log 的每个条目的第一行


[*]增加新文件 git add newfile #执行完此操作后,newfile处于待提交状态,执行git rm --cached newfile,退回到工作目录
  git commit newfile


[*]提交更改    git commit filename
  git commit -a #提交所有更改


[*]查看帮助git help 会列出所有命令 git help command 会给出具体命令的解释
[*]创建新的git仓库
  1. git init   #创建空的仓储
  2. git add .#将当前目录中的所有文件加入到一个临时区域“index”
  3. git commit #持久化"index“中的内容


[*]查看文件差异 git diff(格式需要细看)
  git diff v1:filename v2:filename
  git diff #比较工作目录和index的差异
  git diff --cached#比较index和HEAD的差异
  git diff --cachedcommit #比较index和commit的差异
  git diff HEAD #比较工作目录和HEAD的差异
  git diff commit commit #比较两次提交的差异


[*]查看所有分支 git branch
[*]创建新分支 git branch newbranchname
[*]切换分支 git checkout branchname
[*]查看当前分支的状态 git status
[*]删除分支 git branch -d branchname
[*]解决冲突
  1. git merge branchname #将branchname合并到当前的工作分支
  2. git diff #查看有冲突的文件
  3. 手工解决冲突文件
  4. git commit #提交冲突解决后的文件


[*]gitk#以图形的方式查看仓库的更改历史
[*]比较两个分支的不同
  git fetch git-url branchname
  git log -p HEAD..FETCH_HEAD#控制台方式展现
  gitk HEAD..FETCH_HEAD #图形方式展现


[*]完全恢复原始状态(commit信息会被删除)
  git reset --hard tag


[*]恢复原始状态(commit信息不会被删除)
  git revoke tag


[*]从index中恢复状态
  git checkout -- filename


[*]搜索文件内容
  git grep "要搜索的内容" tag


[*]查看文件
  git show branch:filename


[*]常用的符号
  1.origin:远端的版本
  2. ORIG_HEAD:上一个版本
  git-svn使用方法:
  1. git status 查看当前状态
  在/home/shuiren/repo/mobile/.git/info/exclude中添加ignore
  2. git rebase -i svn/develop
  将重复提交的commit 前面的pick改为s
  3. git svn rebase
  4. git svn dcommit
  sourcer上的git-svn 建立方法(最新)
  

cd~/repo/mobile  

  

  
git svninit   --trunk=trunk   --tags=tags--branches=branches   --prefix=svn/ https://sourcer.yunrang.com/svn/yr/projects/mobile_ads vim .git/config
  
内容如下
  

  

  
repositoryformatversion = 0
  
filemode = true
  
bare = false
  
logallrefupdates = true
  

  
url = https://sourcer.yunrang.com/svn/yr/projects/mobile_ads fetch = mobile/branches/develop:refs/remotes/svn/develop
  

  

  
url = https://sourcer.yunrang.com/svn/yr/projects/mobile_ads fetch = mobile/branches/release1.3:refs/remotes/svn/release1.3
  

  

  

  


  
git svn fetch -R>  
git svn rebase

  
git checkout --track -b>  

  

  

  
git svn fetch -R develop -r79575
  
git checkout --track -b developremotes/svn/develop
  

  
注意 -r 后面的这个版本号, 需要用 tortorisSVN的 showlog功能去看一下 , 你要checkout的这个分支,在历史上有哪些和它相关的 version号, 必须填相关的version才行, 否则是无效的,

  
上面列的这2个version>  

  

  在一个分支上应用一系列commit
  

# Checkout a new temporary branch at the current location   

git checkout -b tmp   

# Move the br branch to the head of the new patchset   

git branch -f br B   

# Rebase the patchset onto tmp, the old location of br   

git rebase --onto tmp A br

删除多个文件 git status -s|grep -P "^ D "|cut -d" " -f 3|xargs git rm
使用svn提交新项目 svn import libra_data_migration https://sourcer.yunrang.com/svn/yr/projects/branches/develop/ads/libra/libra_data_migration -m "initial commit"  

  

路径乱码  

git config --global core.quotepath false  

  



如何用git reflog和git cherry-pick找回已删除的commit记录  

  

git cherry-pick 小结  

git tag -a T_1.0.2.12 ed9b1453f2ff841d120e4524097e2f25502d2181  

git push origin T_1.0.2.12:refs/tags/T_1.0.2.12
页: [1]
查看完整版本: git 笔记