Git 常用命令(2018-03-30)

2018-04-04  本文已影响0人  小的小碰撞

参考廖雪峰的官方网站

常用命令

mkdir test

git 本地仓库关联远程仓库

[root@linux1 php]# git push -u origin master  
To git@github.com:kangvcar/Results-Systems--PHP.git  
 ! [rejected]        master -> master (fetch first)  
error: failed to push some refs to 'git@github.com:kangvcar/Results-Systems--PHP.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing 
hint: to the same ref. You may want to first merge the remote changes (e.g.,  
hint: 'git pull') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


git pull --rebase origin master 
git push -u origin master
或者
git push -f  

git 常用命令

git init

//配置信息
git config user.name manage
git config user.email manage@163.com

//添加项目
git add .

// 提交项目
git commit -m "注释"

// 推送 下拉 项目
git push
git pull

//查看所有版本库日志
git log
git reflog


版本合并

git merge 

Fast forward 模式,表示删除分之后,会丢掉分支信息。
如果要强制禁用Fast forward 模式,Git 就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。

// 第二种合并分支的方法
git merge --no-ff -m "merge with no-ff" dev
-m 参数表示 提交的内容  dev 代表的分支
准备合并dev分支,请注意--no-ff参数,表示禁用Fast forward:

删除本地分支

拉取远程分支并创建本地分支

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

版本回退

//回到当前版本,放弃所有没有提交的修改
git reset --hard HEAD

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

// 回到之前第3个版本
git reset --hard HEAD~(3)

// 回到指定版本
git reset --hard 版本号

回到根目录 查看所有分支

cd ~

git branch -a

Git忽略规则和.gitignore规则不生效的解决办法

#此为注释 – 将被 Git 忽略

*.sample    # 忽略所有 .sample 结尾的文件
!lib.sample    # 但 lib.sample 除外
/TODO    # 仅仅忽略项目根目录下的 TODO 文件,不包括subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt   # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

git rm -r --cached .
git add .
git commit -m 'update .gitignore'
上一篇 下一篇

猜你喜欢

热点阅读