git的一些经常使用命令

1.经常使用命令
git add
git commit -m "xxxxx"
git pull/push
 
2.假如git pull的时候有冲突呢:
Password for 'https://huangliang@git.blizzmi.com':
Updating 1290bd5..ea71164
error: Your local changes to the following files would be overwritten by merge:
slot_server/apps/slot_server/src/lib/lib_mnesia.erl
Please, commit your changes or stash them before you can merge.
 
意思是我台式机上新修改的代码的文件,将会被git服务器上的代码覆盖;我固然不想刚刚写的代码被覆盖掉,看了git的手册,发现能够这样解决:
 
方法1:若是你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)
git stash git pull origin master git stash pop
 
如此一来,服务器上的代码更新到了本地,并且你本地修改的代码也没有被覆盖,以后使用add,commit,push 命令便可更新本地代码到服务器了。
 
方法二、若是你想彻底地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:
git reset --hard git pull origin master
 
注:其中origin master表示git的主分支。
 
 
git stash 先存储本身的
 
git pull origin master 从master上拉取最新代码
 
git stash pop 把本身本地的代码和更新的代码,合并
 
git add ./ 当前文件夹
 
git status 查看状态
 
git --help
 
提交文件
git add ./
git commit -m "xxx"
git push
 
查看状态
git status
 
撤销,回退当前状态
git reset
 
查看当前分支
git branch -a
 
切换分支
git checkout master
 
切换分支,而且更新其余分支的代码到该分支
git checkout newconfig_slot_server
git pull origin develop
 
新建develop分支
git checkout -b dev 本地仓库切换和建立新分支
git branch 查看分支
git push --set-upstream origin dev 提交分支到远程仓库
 
本地拉取分支
git checkout -b develop origin/develop
 
删除本地分支
git branch -D dev_1
删除本地tag
git tag -d tag_v0.1.0
 
删除远程分支
git push origin :branch-name 删除远程仓库
 
git branch -r -d origin/branch-name 只针对本地的远程仓库
 
强制覆盖本地文件
git reset --hard origin/develop
git pull
 
正确的作法应该是
git fetch --all git reset --hard origin/develop
 
撤销add
git reset
 
咱们拿 README.md 这个文件举例,好比修改了一段文字描述,想恢复回原来的样子:
git restore README.md
便可,若是修改已经被 git add README.md 放入暂存队列,那就要
git unstage README.md
git restore README.md
 
 
撤销commit
git reflog
找到须要回退的那次commit的 哈希值,
git reset --hard commit_id 
 
撤销修改
(use "git checkout -- <file>..." to discard changes in working directory)
 
建立轻量标签tag
$ git tag v0.1.2
$ git push origin v0.1.2 # 将v0.1.2标签提交到git服务器
$ git push origin --tags # 将本地全部标签一次性提交到git服务器
 
 
加入不提交队列
git update-index --assume-unchanged apps/slot_lib/src/pb_messages.erl
取消加入不提交队列
git update-index --no-assume-unchanged apps/slot_lib/src/proto/
 
2、拉取远程分支并建立本地分支
方法一
使用以下命令:
git checkout -b 本地分支名x origin/远程分支名x
  • 1
  • 1
使用该方式会在本地新建分支x,并自动切换到该本地分支x。
方式二
使用以下命令:
git fetch origin 远程分支名x:本地分支名x
  • 1
  • 1
使用该方式会在本地新建分支x,可是不会自动切换到该本地分支x,须要手动checkout。
 
 
 
 
 
linux命令行:如何提交上github(貌似必须先上网站建立仓库,后续才能用命令)
先到www.github.com网站上create new repository
而后根据提示操做:
…or create a new repository on the command line
echo "# pb_msgcodegen" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/huang2287832/pb_msgcodegen.git git push -u origin master
 
…or push an existing repository from the command line
git remote add origin https://github.com/huang2287832/pb_msgcodegen.git git push -u origin master
 
 
若是系统中有一些配置文件在服务器上作了配置修改,而后后续开发又新添加一些配置项的时候,
在发布这个配置文件的时候,会发生代码冲突:
error: Your local changes to the following files would be overwritten by merge:
        protected/config/main.php
Please, commit your changes or stash them before you can merge.
若是但愿保留生产服务器上所作的改动,仅仅并入新配置项, 处理方法以下:
git stash git pull git stash pop
而后可使用 Git diff -w +文件名 来确认代码自动合并的状况.
 
反过来,若是但愿用代码库中的文件彻底覆盖本地工做版本. 方法以下:
git reset --hard git pull
其中 git reset是针对版本,若是想针对文件回退本地修改,使用
[plain]  view plain  copy
  1. git checkout HEAD file/to/restore  
 
 
请求合并分支:
 
 
合并分支:
 
git checkout master
 
git pull
 
git merge develop
 
git push
 
而后删除远程分支:
 
git push origin :develop 删除远程分支
 
git branch -D dev_1 删除本地分支
 
开发新内容:
git checkout -b dev _1 从新拉分支
 
从新建develop分支
git checkout -b dev 本地仓库切换和建立新分支
git branch -a 查看分支
git push --set-upstream origin dev 提交分支到远程仓库
git branch -a
 
解决冲突神器:
git fetch origin develop 先把远程develop拉到本地
而后再说使用develop
git checkout origin/develop -- apps/slot_server/src/pp/pp_slot.erl
相关文章
相关标签/搜索