Git基本使用

一、用户信息配置及查看

配置

git config --global user.name "your name(git用户名)"

git config --global user.email "your email(git注册时的邮箱)"

如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。

如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。

查看

查看当前用户:git config user.name

查看当前邮箱:git config user.email

版本查看:git --version

二、Git的基本操作(以新建的readme.txt为例)

克隆:git clone [git地址]

拉取远程仓库项目:git pull <远程主机名> <远程分支名>:<本地分支名>(eg:git pull origin master)

添加远程仓库:git remote add [远程仓库名] [git仓库地址]

查看远程仓库地址:git remote -v

查看工作目录状态:git status

  1. On branch master
  2. Initial commit
  3. Untracked files:
  4. (use "git add <file>..." to include in what will be committed)
  5. readme.txt
  6. nothing added to commit but untracked files present (use "git add" to track)  

  输出结果显示,readme.txt处于未跟踪状态(untracked files),也就是说该文件未存入代码库中,仅保存在工作目录中。

  要将readme.txt提交到远程代码库,需要进行三步操作git add、git commit、git push。

提交的三步

git add 文件名(eg:git add readme.txt)

git commit -m "备注信息"(eg:git commit -m "add readme")

git push [选项] [远程代码库名称] [分支名称](eg:git push origin master)

查看文件发生的变化:git diff 

将暂存区的内容回滚到本地代码库:git reset HEAD

创建分支:git branch [分支名]

切换分支:git checkout [分支名]

合并分支到主干git merge origin/branch(tip:执行前要先使用fetch子命令获取分支:git fetch origin branch)

 移除远程仓库:git rm <file>(强制删除用-f)

 

 

 

                                                      Git存储过程

posted @ 2019-12-15 23:03  walkwater  阅读(122)  评论(0编辑  收藏  举报