美文网首页
git 指南

git 指南

作者: 人间草木_rjcm | 来源:发表于2018-03-27 09:55 被阅读0次

    Git 在线学习:http://gitbook.liuhui998.com/index.html

    电子书《Pro Git》中文版.pdf

    一个文件在 git 中有几种状态:

    1. 未添加状态: 未添加到 git ;     使用 git add file 添加到 git ;  

    2. 已同步状态: 添加到 git 且无改动,与本地和远程库同步;    no todo

    3.  本地未提交状态: 添加到 git 且有改动,与本地和远程未同步;    git commit -m 'some desc'

    4.  本地已提交状态: 添加到 git 且有改动, 添加到本地,与远程为同步;   git push origin 远程分支名

    git  clone  https://gitee.com/kkalarm/pangu-core.git

    查看远程分支:  git branch   -a

    查看本地分支:  git branch  

        git branch -a | grep 'branchsearch'     搜索自己感兴趣的分支; 

    新建分支:  git branch branch_name

    删除本地分支:  git branch -d branch_name

    重命名分支: git branch -m oldbranchname  newbranchname

    4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系

             git push origin branchname

         c.远程没有有remote_branch分支并,本地已经切换到local_branch

            git push origin local_branch:remote_branch

    删除远程分支:  git push origin :branchName

    切换到指定分支:  git checkout branch_name         

    git pull           先同步代码到本地

    git status

    git add .        将所有文件改动添加到本地追踪状态;

    git commit -m "some comments"        提交改动到本地库;

    git push origin  branch_name    

    git pull  or git fetch     拉取远程库的所有分支及信息  

    git commit --amend     将本次提交与上次提交合并为一次提交,提交到本地库;

    git reset --hard commitId     将代码还原到  commitId 对应的提交的历史快照; commitId 之后的所有提交都被销毁;

    git reset --soft commitId     将代码还原到  commitId 对应的提交的历史快照, commitId 之后的文件将变成待提交状态;

    git checkout -b 分支名 (hotfix/xxx or feature/xxx)     在当前分支的基础上创建新的分支;

    git reset HEAD file 将指定文件从已提交状态改为本地未提交状态;

    git checkout -- file 将指定文件从本地未提交状态改为与本地同步状态;

    git log 查看提交记录,特别要记录 commitId, 唯一标识每次提交的代码快照;

    git cherry-pick commitId 将其他分支的某次提交移动到当前分支上;

    git add , git checkout -- ,  git reset HEAD 支持对批量文件的模糊匹配

    回退处理:

    1. 本地工作区中的 文件 filename 已修改,未执行 git add 操作 ;  撤销修改:

    git  checkout  --  filename   (撤销对 filename 文件的修改)

    git checkout  .                     (撤销对所有文件的修改)

    2. 文件 filename 被修改,并且已经被 git add  到 暂存区:

    git reset HEAD filename   (把暂存区的修改回退到工作区)

    git checkout  -- filename   (撤销暂存区的文件修改)

    2. 修改已经 commit 到本地:

    HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id。

    穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本。

    要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。

    相关文章

      网友评论

          本文标题:git 指南

          本文链接:https://www.haomeiwen.com/subject/thjjcftx.html