git常用命令

蓝科迪梦
2022-08-11 / 0 评论 / 111 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年08月11日,已超过596天没有更新,若内容或图片失效,请留言反馈。
初始化当前目录
git init


将指定文件加入缓存区 -A表示所有
git add -A


克隆远程项目
git clone +项目地址


克隆指定分支
git clone -b +分支名 +项目地址  
例如
git clone -b "2019年11月11日10时55分00秒" "https://gitee.com/bufanyun/www.git"


标记更新内容
git commit -m "标记内容"


关联本地仓库和远程仓库 首次需要
git remote add origin  


push代码到git项目  -f表示强制操作不需要更新本地
git push origin master -f



push代码到git项目指定分支   web是master下的一个分支
git push origin master:web -f



git拉取远程分支到本地,同步
git pull origin master







################新增项目时还需要更新xshell密匙或者关联账户身份


1.更新xshell密匙

ssh-keygen -t rsa -C "mengshuai@gitee.com"  然后一直回车直到结束

生成成功以后将/root/.ssh/id_rsa.pub文件下的秘钥复制到码云后台ssh秘钥添加的地方

关键远程仓库地址时应该使用shh方式,

 
 
2.关联账户身份

git config --global user.name "133814250"
git config --global user.email "133814250@qq.com" 



# 然后输入一次用户密码,再根据自己的需求执行下面的任意一条命令

1、设置记住密码(默认15分钟):
git config --global credential.helper cache
 
2、如果想自己设置时间,可以这样做:
git config credential.helper 'cache --timeout=3600'
这样就设置一个小时之后失效
 
3、长期存储密码:
git config --global credential.helper store
 
4、增加远程地址的时候带上密码也是可以的。(推荐)
http://yourname:password@git.oschina.net/name/project.git

 
 
如果之前已有关联git信息,还需要

git remote rm origin #清空之前的设置仓库权限信息
git remote -v
git remote add origin git@gitee.com:bufanyun/ml.git  #关联
git push origin master -f
 
 
克隆远程库到本地
git clone -b "2019年11月11日10时55分00秒" "https://gitee.com/bufanyun/www.git"
 
分支名 远程仓库地址






##############其他

新建分支推送项目:https://blog.csdn.net/weixin_46654114/article/details/122612824


如何忽略掉特定文件,push到github上

如果不是首次push,服务器会缓存之前.gitignore文件的信息,修改完.gitignore后需要执行:git rm -r --cached .

确保文件.gitignore存在,如果不存在创建即可
然后在文件中加入想要忽略的文件即可
举个例子:

.idea
.vs/
.htaccess
*/.DS_Store
.DS_Store
composer.lock
.php_cs.cache
.env
vendor

php_errors.log
composer.phar

404.html
index.html

config/.config.php
config/.config.php.bak

public/ssr-download/
public/images/*.*
public/theme/material/css/images/bg

storage/framework/smarty/cache/*
storage/framework/smarty/compile/*
storage/framework/views/*
storage/*.*
/storage/traffic_notified/
!storage/framework/smarty/cache/.gitkeep
!storage/framework/smarty/compile/.gitkeep
!storage/framework/views/.gitkeep

.user.ini
public/.user.ini


# 忽略本地某一文件更改,不提交

比如有一个文件: config.php 里面有一些本地开发环境参数,不需要提交

git update-index --assume-unchanged config.php
执行
git status
就看不到config.php 文件了

如果需要提交config.php文件了,执行:

git update-index --no-assume-unchanged config.php
执行
git status
就可以看到config.php了,这时就可以提交了



gitee的直接拉取仓库子文件链接格式

如:https://gitee.com/bufanyun/live-push-pull/raw/master/manifest.json

https://gitee.com/bufanyun/仓库名称/raw/分支名称/需要拉取的文件路径+名称
0

评论

博主关闭了所有页面的评论