持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第16天,点击查看活动详情 原文链接:Dev Jain
git config
- 在使用git之前,必须进行配置!
- 使用此命令可以指定提交代码时的用户名和电子邮件地址
#set up git with your name
git config --global user.name <username>
#set up git with your email
git config --global user.email <useremail>
git init
- 必须先创建一个 git 存储库,然后才能进行提交或对其执行任何其他操作
- 此命令用于创建新的 git 存储库(创建 .git 目录)
git init
git clone
- 它用于创建远程存储库的本地副本
- 它使用远程 URL 访问存储库,例如github的.git仓库地址!
git clone <repo URL you want to clone>
git add
-
使用 git add 将文件从工作目录移动到暂存区
-
git add 将您的修改存储到一个文件中,允许您将本地版本与远程存储库中的版本进行比较
-
在提交之前使用 git add 将新文件添加到暂存区
# to add a file
git add <filename>
# to add all files
git add .
git commit
-
此命令记录带有修改 ID 的日志消息
-
使用 git commit 可以保存对本地存储库所做的更改
-
每次提交代码更改时,都必须在提交消息中包含更改的说明信息
git commit -m "commit message"
git push
- 此命令用于将对本地存储库所做的更改推送/上传到远程存储库
- 这里 git push origin (origin 表示远程) master (主分支名称)
git push origin master
git branch
- 这个命令让你创建、列出、重命名和删除分支
#to view list of all branches
git branch
#to create new branche
git branch "branch name"
#to delete a branch
git branch -d "branch name "
git switch
- 此命令用于切换到现有分支或使用 (-b) 标志创建并同时切换到新分支
#to switch to another branch
git checkout "branch name"
#to create new branch and switch to it
git checkout -b "branch name"
git log
-
此命令显示到目前为止对当前分支所做的所有提交的日志
-
它用于列出当前分支的当前版本历史
git log
## git merge
-
该命令用于合并两个分支的变化
-
如果没有冲突,那么您的更改将被合并
-
如果发生合并冲突,开发人员需要首先解决冲突而不是合并更改
-
在运行 git merge 命令之前,您应该在要与父分支合并的分支上
git merge "name-of-branch-to-merge"