`

git 命令

阅读更多

1.git配置方法

    git config --list  查看git的配置信息

    git config --global user.name “name"

    git config --global alias.co checkout  简写命令,–global是全局参数,指在当前用户的所有git仓库都适用

2.git文件状态

    unstaged-仓库无此文件记录

    modified-文件处于修改状态

    staged-被暂时保存

    commited-被提交到仓库

 

3.git基本操作

    git status 查看文件状态

    git diff 查看文件修改

    git add <newFile> -将文件加入到暂存区

        git commit -m ‘massage’ 将追加提交到仓库

        git rm --cache <newFile> 将文件恢复为unstaged

        git reset HEAD <newFile> 将文件恢复为unstaged

        git rm -f <newFile> 将文件彻底删除

 

    vim <newFile> 文件为modified状态

        git add <newFile> 将文件状态变为staged状态

            git reset <newFile> 变为modified状态

            git commit -m ‘massage’ 将修改提交到仓库

            git checkout <newFile> 摈弃修改

 
    git rm <newFile>  删除了文件,为staged状态

        git commit -m ‘massage’ 从仓库中删除文件

        git reset HEAD <newFile>  将文件恢复为unstaged

    git rm -- cache <newFile>  暂时删除了文件,在目录中仍存在

 

4.远程仓库

    git init  初始化仓库,当前目录下多了.git的目录,是Git跟踪管理版本库的,可以用ls -ah命令看见

    git clone <url>  clone仓库

    git remote add origin <url> 新建远程仓库

    git remote rm origin 删除远程仓库

    git remote rename origin <newName> 更改仓库名  

    git remote -v  查看所有仓库信息

    git remote show origin 查看单个仓库信息

    git pull 更新本地仓库

    git push origin <branchName> 更新远程仓库

  5.标签

    git tag <tagName> 新建tag

    git tag -a <tagName> -m 'massage' 带标注

    git tag -a <tagName> <commit号> 以commit号为止添加tag

    git tag 查看所有tag

    git show <tagName> 查看某tag信息

    git tag -d <tag-name> 删除tag 

     git push origin :refs/tags/<tagname>删除远程标签

     git push origin <tagname>推送一个本地标签

    git push origin —tags提交所有标签到远程仓库

  6.分支管理

 

    git branch 查看分支

    git branch -r 查看远程分支

    git branch -v查看所有分支详细信息

    git branch --set-upstream branch-name origin/branch-name 指定本地dev分支与远程分支的链接

    git checkout branchName 切换分支

    git branch newBranch新建分支

    git checkout -b newBranch 新建分支并切换到分支上

    git checkout --track -b branch origin/branch 从远程分支中创建本地分支,track现在已不需要

    git merge branchName 将其他分支合并到当前分支中

    git branch -d branchName 删除分支

    git push origin :branchName 删除远程分支

    git stash 储存当前工作现场

    git stash list查看工作现场列表

    git stash pop

    git log 查看当前分支提交日志

    git log --graph --pretty=oneline --abbrev-commit 查看分支合并情况

    git reflog 查看所有记录

    git reset --hard HEAD^ 回退到上一个版本

    git format-patch -1 提取本次 commit 和上次 commit 之间的不同, 并生成patch文件

    git format-patch -2 提取本次 commit 和 上上次 commit 之间的不同, 并生成patch文件

    git format-patch commit号1 commit号2 提取2次commit号之间的不同, 并生成patch文件 (commit号可以通过 git log 来查看)

    git format-patch tag1 tag2 提取2次tag之间的不同, 并生成patch文件 (tag可以通过 git tag 来查看)

    git rebase http://iissnan.com/progit/html/zh/ch3_6.html

 

2、git 删除远程文件

git rm -rf 文件/文件名(.idea)

git commit -am 'xxxx'

git push origin 分支名

git rm --hard

git rm *.xx

git branch -D feature-pan 删除本地分支 feature-pan

git branch -d r origin/feature-pan 删除远程分支 feature-pan

git checkout -b feature-pan  新建分支并切换到分支上

git push origin :feature-pan 删除远程分支 feature-pan

 

git解决分支冲突

1、在当前工作分支feature-pan: git rebase origin/release 获取远程分支release的代码

2、merge代码:按住command + 9 显示冲突文件,进行merge代码

3、git add .  添加修改过后的代码

4、git rebase --continue 继续解决冲突,由于可能会提交多次,造成多次冲突

5、其中会有些commit 会出现无更改,然后可以用 git rebase --skip 略过此次提交

6、重复2、3、4、5 步骤,直至冲突完全解决

7、git commit -am ‘u:rm xxxxx ’

     git push origin feature 提交代码

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics