• Git学习笔记(持续更新)


    1.强制同步为远程的代码

    远程仓库回退了commit的情况下(第2条描述之情况),强制同步远程的代码到本地

    #更新远程最新的所有代码,但是不merge或者rebase
    git fetch --all
    
    #直接reset到master,也就把刚才fetch的更新了
    git reset --hard origin/master

    2.回退版本

    #回退本地版本
    git reset --hard <commit_id>
    
    #强制提交到服务器
    git push origin HEAD --force 

    3.新建分支和远程分支

    #新建本地分支
    git checkout -b branch_name
    
    #推送到远程
    git push origin branch_name
    
    #设置跟踪(默认的git pull和git push,不然需要 git push origin branch_name来更新)
    #如果第一次推送时,使用git push -u origin branch_name,则可省略这一步
    #git push --set-upstream origin branch_name
    git branch -u origin/branch_name
    
    #协作者使用
    #更新远程branch list
    git fetch origin
    
    #更新远程的新分支到本地,并建立本地分支
    git checkout -b branch_name origin/branch_name
    
    #删除远程分支(传送一个空指针到远程分支,相当于删除)
    git push origin :branch_name
    
    #删除远程分支之后,其他机器同步
    git fetch -p

    4.放弃当前工作区所有的修改

    #放弃单个文件
    git checkout <filename>
    
    #放弃工作区全部修改
    git checkout .

    5.设置当前branch自动提交的远程仓库

    #参考第3条
    git branch --set-upstream-to=origin/<branch> master

    6.保存密码,不用多次输入

    #配置参考第8条配置详解
    git config --global credential.helper store
    
    Linux/Unix下设置失效时间:
    
    #默认15分钟
    
    git config --global credential.helper cache 
    git config --global credential.helper 'cache --timeout=3600'
    
    Windows下设置
    
    #参考http://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command
    #没有配置成功,待测试
    git config --global credential.helper wincred

    7.二进制文件冲突的解决

    git pull
    
    #使用对方的文件覆盖自己的
    git checkout --theirs YOUR_BINARY_FILE
    
    #使用自己的文件覆盖对方的
    // git checkout --ours YOUR_BINARY_FILE
    git add YOUR_BINARY_FILE
    git commit -m 'merged with the remote repos.'
    git push

    8.git config 配置详解

    git config [--local|--global|--system] 分别代表本地(当前库) 全局 系统参数

    一般系统参数不会改

    #得到全部全局设置变量
    git config --global -l
    
    #得到本地配置中user.name的值
    git config --local --get user.name
    
    #设置本地中user.name的值为 mygit
    git config --local --set user.name mygit
    
    #删除本地配置中user.name的值
    git config --local --unset user.name

    9.重新刷新忽略文件

    对于已经push的文件,再加到.gitignore中,就不起作用了,需要使用下面命令来刷新之后,重新提交

    git rm -r --cached .
    git add .
    git commit -m 'update-gitignore'

    10.合并时 , 只合并其中一个commit

    git cherry-pick c0c0b5d6[commit编号]

    11.拉取远程项目

     1) 本地没有目录

    git clone http://xxx.com/xxx.git
    cd xxx
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

     2) 本地已经创建了目录existing_folder

    cd existing_folder
    git init
    git remote add origin http://xxx.com/xxx.git
    git add .
    git commit -m "Initial commit"
    git push -u origin master

    12.本地分支取消和远程分支的关联

    #本地分支取消和远程分支的关联
    git branch --unset-upstream branch_name

    13.tag管理

    #轻量标签(无备注)
    git tag [tagName]
    #带备注
    git tag -a [tagName] -m "备注"
    #删除TAG
    git tag -d [tagName]
    
    #列出所有标签
    git tag
    #过滤
    git tag -l "v0.9.*"
    
    #查看标签详情
    git show [tagName]
    
    #推送到远程
    git push origin [tagName]
    #删除远程TAG
    git push origin :refs/tags/<tagName>
    #推送本地的全部tag
    git push origin --tags
    #可以切换到分支
    git checkout [tagName]
  • 相关阅读:
    [转][ASP.NET MVC]如何定制Numeric属性/字段验证消息
    [转]how can I change default errormessage for invalid price
    [转]超详细图解:自己架设NuGet服务器
    [转]C#委托Action、Action<T>、Func<T>、Predicate<T>
    自定义Image HtmlHelper
    OAuth 开放授权 Open Authorization
    [转]巧克英语
    Radis
    MongoDB
    [转]asp.net 跨域单点登录
  • 原文地址:https://www.cnblogs.com/kreo/p/4217451.html
Copyright © 2020-2023  润新知