女友难以记住Git命令?这里有几个实用的解决方案!

如果你也和我女朋友一样总是忘记Git命令,觉得记忆Git命令是很枯燥和麻烦的事情。我写了一个包含了40 条常用Git命令的清单。你一定要收藏起来,当你忘记Git命令的时候,就可以打开来查看啦!!!

1.初始化本地仓库

git init <directory> 

<directory>目录是可选的。如果没有指定,默认使用当前目录

2.克隆一个远程仓库

git clone <url>

3.添加一个文件到暂存区

git add <file>

如果要添加当前目录中的所有文件,请使用.代替<file>.

git add .

4.提交更改

git commit -m "<message>"

如果您想添加跟踪文件的所有更改(包括最新的修改)并提交

git commit -a -m "<message>"

# or

git commit -am "<message>"

5.从暂存区里删除一个文件

git reset <file>

6.移动或重命名文件

git mv <current path> <new path>

7.从存储库中删除文件

git rm <file>

你也可以仅使用标志符将其从暂存区中删除--cached

git rm --cached <file>

Git 基本概念

  1. 默认分支的名称:main
  2. 默认远程仓库的名称:origin
  3. 当前分支查询:HEAD
  4. 当前分支的父母查询:HEAD^HEAD~1
  5. 当前分支的祖父母查询:HEAD^^HEAD~2

13.查看当前有哪些分支

git branch

常用的标识符

  • -a:查询所有分支(本地和远程)
  • -r: 查询远程分支
  • -v: 查询最后一次提交的分支*
  • 14.创建分支

    git branch <branch>
    

    您可以创建一个新分支并使用checkout命令切换到你新创建的分支下。

    git checkout -b <branch>
    

    15.切换分支

    git checkout <branch>
    

    16.删除分支

    git branch -d <branch>
    

    您还可以使用标识符-D 强制删除分支。

    git branch -D <branch>
    

    17.合并分支

    git merge <合并到当前分支>
    

    常用的标识符

  • --no-ff:创建合并并且提交
  • --squash:将指定分支的所有commit记录合并成一个
  • 不建议使用--squash 标识符,因为它会将所有提交合并成一个提交,从而导致提交历史记录混乱

    18. Rebase

    Rebase变基是将一系列提交移动或组合到新的基础提交的过程

    image.png

    git rebase <branch to rebase from>
    

    19. 检查之前的提交

    git checkout <commit id>
    

    20. 恢复提交

    git revert <commit id>
    

    21.重置提交

    git reset <commit id>
    

    你还可以添加--hard标识符来删除所有更改,但是一般不建议使用。

    git reset --hard <commit id>
    

    22.检查存储库的状态

    git status
    

    23.显示提交历史

    git log
    

    24.显示未暂存文件的变化

    git diff
    

    你还可以使用--staged标识符来显示对暂存文件的更改。

    git diff --staged
    

    25.显示两次提交之间的变化

    git diff <commit id 01> <commit id 02>
    

    26. 隐藏变化

    stash允许您临时存储更改而不提交到代码仓库 。

    git stash
    

    我们还可以向stash添加一条说明信息。

    git stash save "<message>"
    

    27. 查看现有stash

    git stash list
    

    28.拉取stash

    拉取stash不会把当前的stash从stash列表中删除。

    git stash apply <stash id>
    

    如果不指定<stash id>,将应用最新的stash(适用于所有类似的stash命令)

    你还可以使用格式stash@{<index>}来应用stash(适用于所有类似的stash命令)

    git stash apply stash@{0}
    

    29. 删除stash

    git stash drop <stash id>
    

    30. 移除所有stash

    git stash clear
    

    31.重新应用缓存的stash

    git stash pop <stash id>
    

    32. 查看stash的变化

    git stash show <stash id>
    

    33.添加远程仓库

    git remote add <remote name> <url>
    

    34. 查询远程仓库

    git remote
    

    添加一个-v标识符用来查询远程存储库的URL

    git remote -v
    

    35.删除远程仓库

    git remote remove <remote name>
    

    36 重命名远程仓库

    git remote rename <old name> <new name>
    

    37. 从远程存储库拉取代码

    git fetch <remote name>
    

    38. 从特定分支获取

    git fetch <remote name> <branch>
    

    39. 从远程存储库中拉取更改

    git pull <remote name> <branch>
    

    40. 将更改推送到远程存储库

    git push <remote name>
    

    41.将更改推送到特定分支

    git push <remote name> <branch>
    
    物联沃分享整理
    物联沃-IOTWORD物联网 » 女友难以记住Git命令?这里有几个实用的解决方案!

    发表评论