Git命令操作
2024-10-07 17:06:57
安装配置
将其bin目录添加到path
ssh -keygen -t rsa -C 自己的邮箱(获取ssh远程连接秘钥)
使用:
进入项目目录 右击进入git bash 执行git init
github上new一个新仓库复制生成的例如:git@github.com:qinyios/mygitproject.git
然后执行git remote add origin git@github.com:qinyios/mygitproject.git 和远程仓库建立项目的联系 命令 git add 本地文件提交到暂存区
git commit 暂存区提交到本地仓库
git push将本地仓库的内容推送到远程仓库
git pull将远程仓库的内容拉取到本地仓库 第一次发布项目
ssh-keygen -t rsa
git add .
git commit -m “注释内容”
git remote add origin git@github.com:qinyios/mygitproject.git
git push -u origin master git clone 第二次提交:git push origin master 如果报错:To github.com:qinyios/mygitproject.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:qinyios/mygitproject.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 integrate the remote changes
hint: (e.g., '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 origin master git add 将文件添加进暂存区
git commit 将文件提交到本地分支
git checkout + 分支名字 切换分支
git checkout -b dev 创建并切换分支到dev
git branch 命令会列出所有分支,当前分支前面会标一个*号
git merge dev 把dev分支的工作成果合并到master分支上
git branch -d dev 删除dev分支//强制删除方法git branch -D dev;强制删除原因是远程分支删除了,本地还没删除所以要强制删除
git log --graph 命令可以看到分支合并图
git checkout --filename 把文件从工作区中修改的部分撤销
git reset HEAD readme.txt 可以把暂存区的修改撤销掉,重新放回工作区
git status 查看状态
git rm test.txt + git commit -m "remove test.txt" 删除文件并提交
git push origin +分支名字 把本地库的所有内容推送到远程库上 git stash 把当前工作现场“储藏”起来,等以后恢复现场后继续工作
git stash pop恢复的同时把stash内容也删了
git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除 git remote -v 查看远程库的信息
git clone 从远程库clone
git branch --set-upstream branch-name origin/branch-name建立本地分支和远程分支的关联
最新文章
- LOL(英雄联盟)提示不支持虚拟机登录,解决方法
- 磁盘阵列RAID原理、种类及性能优缺点对比
- DP大作战—组合背包
- 彻底禁止QQ更新
- guava学习--Optional可空类型
- hdu 4301(基本dp)
- 编译vo-aacenc遇到的问题
- Swift进阶
- iOS查错机制
- ubuntu修改环境变量
- Java中用正则表达式找出数字
- Redis【入门】就这一篇!
- FireDac 的一些应用提示
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习4
- Java控制台常用命令
- android 知识点汇总
- Mybatis 查询tinyint(1)的数据库字段时会自动转换成boolean类型
- Linux 下crontab 详解转
- 【JavaScript 从零开始】表达式和运算符(2)
- 【转载】注释AFX_MSG_MAP,AFX_DATA,AFX_DATA_MAP , Afx_MSG等宏不能删除