Git

git 某个文件变更记录 -----------------
git whatchanged [file]
显示某个版本的修改详情
git show 6edc4bdcc1c966dc
git log -p 6edc4bdcc1c966dc

git tag使用 -------------------------------

git tag  //查看tag
git tag test_tag c809ddbf83939 //在某个commit 上打tag
git tag

git push origin test_tag    //!!!本地tag推送到线上

git tag -d test_tag        //本地删除tag
git push origin :refs/tags/test_tag    //本地tag删除了,再执行该句,删除线上tag

git show xxx  //显示某个tag所在的commit的修改

git 删除未跟踪的文件-------------------------
在编译git库拉下来的代码时,往往会产生一些中间文件,这些文件我们根本不需要,尤其是在成产环节做预编译,检查代码提交是否能编译通过这种case时,我们往往需要编译完成后不管正确与否,还原现场,以方便下次sync代码时不受上一次的编译影响。
# 删除 untracked files
git clean -f
# 连 untracked 的目录也一起删掉
git clean -fd
# 连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)
git clean -xfd
# 在用上述 git clean 前,强烈建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删
git clean -nxfd
git clean -nf
git clean -nfd

git 删除分支---------------------------
git branch -d <分支名>

git clone 远程指定分支------------------------------
git clone -b [remote repository address]

git log 方便看 ------------------------------------------参考
git config --global alias.lm “log --no-merges --color --date=format:’%Y-%m-%d %H:%M:%S’ --author=‘你的名字!自己修改!’ --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset’ --abbrev-commit”

git config --global alias.lms “log --no-merges --color --stat --date=format:’%Y-%m-%d %H:%M:%S’ --author=‘你的名字!自己修改!’ --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset’ --abbrev-commit”

git config --global alias.ls “log --no-merges --color --graph --date=format:’%Y-%m-%d %H:%M:%S’ --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset’ --abbrev-commit”

git config --global alias.lss “log --no-merges --color --stat --graph --date=format:’%Y-%m-%d %H:%M:%S’ --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset’ --abbrev-commit”

git 查看commit提交内容-------------------------------
查看最新的commit : git show
查看指定commit hashID的所有修改:git show commitId
查看某次commit中具体某个文件的修改:git show commitId fileName

git 查看远程仓库地址------------------------------------

git remote -v

学习文档1
学习文档2

git 只拉取远程仓库的某个分支-------------------------------------

git clone -b <branch name> [remote repository address]

git 查看修改变动-------------------------------------

git log 查看commit的历史
git show <commit-hash-id>查看某次commit的修改内容
git log -p <filename>查看某个文件的修改历史
git log -p -2查看最近2次的更新内容

git diff  >没有被add的
git diff --cached  >add但是没有commit的
git diff 版本1 版本2 src  >比较src在1和2的区别 

git 重命名远程分支-----------------------------------

  1. 删除远程分支:
$ git push --delete origin devel
To git@github.com:zrong/quick-cocos2d-x.git
 - [deleted]         devel
  1. 重命名本地分支:
git branch -m devel develop
  1. 推送本地分支:
$ git push origin develop

git 获取远程分支到本地-------------------------------
git fetch origin :
或者git fetch后 git checkout -b localname origin/remote_branchname

git 撤销merge操作------------------------------------
先通过 git reflog 或者 gitg、gitk、qgit 等工具确定 merge 之前 master 所在的 commit,然后在 master 分支上使用 git reset --hard 重置头指针。一般来说,在 master 上直接执行 git reset --hard HEAD~ 也可以回到合并之前的提交,但 git reset --hard 命令还是使用确定的 commit 为好。注意,git reset --hard 命令有风险,除非十分确定要放弃当前提交,否则最好先 git branch 为当前的提交建立个新的分支引用后再继续,待确定无误后删除即可

pull/push每次都要输入name和pwd------------------------------

  1. git config --global credential.helper store
  2. git pull / git push

Config---------------------------------
git config --global user.name “changyu.tu”
git config --global user.email "changyu.tu@aispeech.com"
-and you can also add many key-value just use -> git config --global --add user.name fawn
-and when you can use -> git config --get user.name / git config user.name , you will get the last add value.
-and use ->git config --list ->to see the config information.
-and use ->git config --global --unset user.name [fawn]-> to remove this setting.
-and use ->git config --global user.name rain ->to alter the value.
how to choice installed git -> which -a git ->git --version->
alias-------------------------------------------------------------------------------------------------------------------------------
-git config --global alias.ck checkout
-git config --global alias.br branch
-git config --global alias.st status
-git config --global alias.ci commint
-git config --global alias.lol “log --oneline” ->方便看日志
help-------------------------------------------------------------------------------------------------------------------------------
if you don’t know how to do . use -> git help [command] / git command --help/man git -command.
use

git init [dir] / git clone [https] ->to build a git store.

git pull == git fetch + git merge

origin branch cover local-----------------不需要再傻傻的新建一个目录clone了—
git fetch --all
git reset --hard origin/master

git checkout commit_id----------------------------------------------------------------------------
得到一个detached 状态 。如果你这时做了个 commit, 那么这个 commit 就是属于一个新分支的,但如果不给这个新分支命名,然后又 checkout 了其他分支,那么这个新分支的引用计数就变为0了,会被回收。

拷贝当前分支代码作为一个新分支-------------------------------
git checkout -b new_branch_name

git cherry-pick ---------------------------将其他分支的一些commit提交 merge到当前分支---------------------------------------
git checkout old_cc
$ git cherry-pick 38361a68 # 这个 38361a68

$ git log
commit 38361a68138140827b31b72f8bbfd88b3705d77a

1. 如果顺利,就会正常提交。结果:
Finished one cherry-pick.# On branch old_cc# Your branch is ahead of ‘origin/old_cc’ by 3 commits.
2. 如果在cherry-pick 的过程中出现了冲突
Automatic cherry-pick failed. After resolving the conflicts,mark the corrected paths with 'git add ’ or 'git rm 'and commit the result with: git commit -c 15a2b6c61927e5aed6718de89ad9dafba939a90b
就跟普通的冲突一样,手工解决:2.1 $ git status # 看哪些文件出现冲突
both modified: app/models/user.rb
2.2 $ vim app/models/user.rb # 手动解决它。 2.3 $ git add app/models/user.rb2.4 git commit -c <新的commit号码>
来源: http://blog.csdn.net/wh_19910525/article/details/7554430

git 本地仓库push到远程-------------------------------------------------------------------------------------------------------------------

git remote add origin 你的远程库地址  // 把本地库与远程库关联
git push -u origin master    // 第一次推送时
git push origin master  // 第一次推送后,直接使用该命令即可推送修改

git LF CRLF问题----------------------------------------------
warning: LF will be replaced by CRLF in
解决:
git config core.autocrlf false

git 根据commit查找分支-------------------------------
git branch --contains CommitId

git 不同版本文件对比-------------------------------
git --diff <commit_id1>:<filePath/file> <commit_id2>:<filePath/file>

git 拉取远程分支到本地-------------------------------

git branch -r
git checkout -b 本地分支名 origin/远程分支名

git 更快的拉取一个分支-------------------------------
git checkout -b tmp
git fetch origin aios-release-zhangxun
git reset --hard

git pull 和 git fetch区别-------------------------------
git pull = git fetch + git merge origin/xxx
一般git fetch更安全
参考 fetch origin mastergit log -p master…origin/mastergit merge origin/master)

git 撤销操作-------------------------------
$ git checkout . 撤销所有修改如果有新增文件(git checkout . && git clean -df)

git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

git 远程覆盖本地分支-------------------
git fetch --all
git reset --hard origin/master
git fetch 只是下载远程的库的内容,不做任何的合并 git reset 把HEAD指向刚刚下载的最新的版本
参考1

git 将没跟踪的文件清理-------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值