关于git使用的整理笔记


(声明:本教程仅供本人学习使用,如有人使用该技术触犯法律与本人无关)
(如果有错误,还希望指出。共同进步)


本地项目上传Github

一、仓库配置公钥

1、打开自己的github,如图点击右上角头像,在下拉菜单中选中【Settings】
操作一
2、选中 【SSH and GPG keys】,在弹出的菜单框中选中 【New SSH key】
操作二
3、在 【Title】 填入你为你公钥起得名字,在 【Key】栏中粘贴你的 【公钥】, 一般文件名为 【.ssh/id_rsa.pub】
操作三


二、新建仓库

1、如图依次点击进行仓库创建
在这里插入图片描述

2、在填入一些东西后,你的仓库就建好了
在这里插入图片描述
3、创建完成后的页面
在这里插入图片描述

这里要注意:

在使用”本地创建仓库关联到此仓库“的这种方法时,需注意:
1、须在要上传的项目内新建一个"README.md"文件
2、在文件中写入”# 【你这个仓库的名字】“
3、如果需要上传文件夹中的所有文件,就把使用”git add * “替换”git add README.md“

Git的使用

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

常用命令详解

【usage】

git --version				# 打印git的版本
git --help					# 打印git常用命令和概要,如果带上参数”-a”或者”-all“

【working】

git clone					# 克隆一个github项目到本地		
git init					# 创建一个新的本地仓库
 
git status 				# 显示工作路径下已修改的文件
git diff					# 显示与上次提交版本文件的不同
git add * 					# 添加当前所有修改到暂存区
git add -p <file> 			# 交互式选项添加文件到缓存区,会出现可选项
git commit -a				# 提交本地的所有修改
git commit					# 提交之前标记的变化

# 附带注释提交
git commit -m ”提交的注释“ 	

# 提交,并将提交时间设置为之前的某个日期
git commit --date="`date --date='n day ago'`" -am "Commit Message"			

# 修改上次提交【请勿修改已发布的提交记录!!!】
git commit --amend			


# 把当前分支中未提交的修改移动到其他分支
git stash
git checkout branch2
git stash pop


# 从当前目录的所有文件中查找文本内容:
grep "Hello"

# 在某一版本中搜索文本:
git grep "Hello" v2.5


# 从***提交开始,显示所有的提交记录(显示hash, 作者信息,提交的标题和时间):
git log

# 显示所有提交(仅显示提交的hash和message):
git log --oneline

# 显示某个用户的所有提交:
git log --author="username"

# 显示某个文件的所有修改:
git log -p <file>

# 是谁,在什么时间,修改了文件的什么内容:
git blame <file>
# ^c5111b4 (200 2020-08-08 16:42:12 +0800  1) DIALECT = 'mysql'


# 列出所有的分支:
git branch

#切换分支:
git checkout <branch>

# 创建并切换到新分支:
git checkout -b <branch>

# 基于当前分支创建新分支:
git branch <new-branch>

# 基于远程分支创建新的可追溯的分支:
git branch --track <new-branch> <remote-branch>

# 将新建的本地分支与远程分支关联
git branch --set-upstream-to=origin/[远程分支] [本地分支]

# 删除本地分支:
git branch -d <branch>


git remote

# 给当前版本打标签:
git tag <tag-name>

# 列出当前配置的远程端:
git remote -v

# 显示远程端的信息:
git remote show <remote>

# 添加新的远程端:
git remote add <remote> <url>

# 下载远程端版本,但不合并到HEAD中:
git fetch <remote>

# 下载远程端版本,并自动与HEAD版本合并:
git remote pull <remote> <url>

# 将远程端版本合并到本地版本中:
git pull origin master

# 将本地版本发布到远程端:
git push remote <remote> <branch>

# 删除远程端分支:
git push <remote> :<branch> (since Git v1.5.0)
git push <remote> --delete <branch> (since Git v1.7.0)

# 发布标签:
git push --tags


# 将分支合并到当前HEAD中:
git merge <branch>

# 将当前HEAD版本重置到分支中:请勿重置已发布的提交!
git rebase <branch>

# 退出重置:
git rebase --abort

# 解决冲突后继续重置:
git rebase --continue

# 使用配置好的merge tool 解决冲突:
git mergetool

# 在编辑器中手动解决冲突后,标记文件为已解决冲突
git add <resolved-file>
git rm <resolved-file>


# 放弃工作目录下的所有修改:
git reset --hard HEAD

# 移除缓存区的所有文件(i.e. 撤销上次git add):
git reset HEAD

# 放弃某个文件的所有本地修改:
git checkout HEAD <file>

# 重置一个提交(通过创建一个截然不同的新提交)
git revert <commit>

# 将HEAD重置到指定的版本,并抛弃该版本之后的所有修改:
git reset --hard <commit>

# 将HEAD重置到上一次提交的版本,并将之后的修改标记为未添加到缓存区的修改:
git reset <commit>

# 将HEAD重置到上一次提交的版本,并保留未提交的本地修改:
git reset --keep <commit> 

猜你喜欢

转载自blog.csdn.net/weixin_43633797/article/details/107888673