git简单使用

从事计算机软件开发有一段时间了,发现代码管理一直是个头痛的问题,最近花了部分时间来熟悉GIT这个工具,

将使用经历简单做了哈总结. 其中参阅了很多前辈的意见.

1> git初始化配置
git配置主要用于标识库username和email地址
git config --global user.name "You Name"
git config --global user.email you@mail

2> 忽略文档与目录管理
建立.gitignore文件来配置不让git管理的文档类型
如下忽略foldername文件夹全部内容,sln解决方案文件, 配置文件(.gitignore内容如下)
foldername/*
*.sln
*.config

3> 创建git库
创建本地库
git init
添加远程仓库路径,在remote_server_git_url_address创建名字为remote_name的仓库
git remote add remote_name remote_server_git_url_address
显示所有的远程仓库
git remote -v
重名名远程仓库
git remote rename remote_name rename
删除远程仓库
git remote rm remote_name

4> 添加库管理文件
git add folder
git add abs_path_filename

5> 从工作目录和索引中删除文件
git rm -r folder
git rm abs_path_filename

6> 提交工作代码并添加备注
git commit -m "comments"

7> 查看版本库状态
git status

8> 查看历史日志
git log -number
git show

9> 代码合并
将目标分支代码合并到当前分支
git merge curr_branch dst_branch

10> git分支管理
建立分支
git checkout -b new_branch
切换分支
git checkout dst_branch
查看分支
git branch -r
删除分支
git branch -D branch_name
删除远程branchname分支
git branch -d -r branch_name

11> git克隆
git clone remote_server_address

12> 还原对某个版本的更改
git revert commit_id

13> 库的恢复
git reset commit_id

14> 比较两个分支的文件区别
git diff branch_src branch_target

15> 查看分支历史
git-show-branch -all

16> 代码还原
git checkout abs_path_filename

17> 提交代码到远端仓库
本地代码已经head,提交本地local_branch作为远程remote_branch分支
git push origin local_branch:remote_branch
创建远程分支,本地分支push到远程
git push origin remote_branch

18> 更新本地仓库
git pull remote_name local_branch_name

19> 在软件发布时创建标签
git tag tag_name submit_id_first_char10
合并远程仓库的tag到本地:
git pull origin --tags
上传本地tag到远程仓库:
git push origin --tags


20> 丢弃本地更改,到服务器上获取最新版本并将本地主分支指向它
git fetch origin
git reset --hard origin/master
查看远程仓库信息
git remote show origin
使用远程remote_branch分支在本地创建local_branch,如果本地分支存在,则自动合并两个分支
git fetch origin remote_branch:local_branch

21> 将当前没有提交的工作存入git工作栈中
git stash

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值