每个开发者都必须知道的基本 Git 命令🚀🚀
【摘要】 git config在使用git之前,必须进行配置!使用此命令可以指定提交代码时的用户名和电子邮件地址#set up git with your namegit config --global user.name <username>#set up git with your emailgit config --global user.email <useremail> git init必...
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"
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)