git命令

 

  学习git命令前,我们可以先学习下git的基本流程  

  step1:  remote repositroy --(fetch/clone)--> local repositroy

  step2:  remote repositroy--(pull)--> workspace

  step3:  workspace --(add)-->staging area, local repositroy checkout workspace, 没有冲突,staging area --(commit)--> local repositroy --(push)-->remote repositroy

 

  创建git仓库命令:

  git init  在一个空的文件夹下 git init   初始化空git仓库完成,在该文件目录中会生成一个.git子目录。

  git clone  [github上的项目url]  将目标项目拷贝到当前目录

  git clone  [github上的项目url] [newProjectName]  将目标项目拷贝到当前目录,并修改一个新的项目名称。

  

  提交与修改

  git add [file1] [file2]   添加一个或多个文件到staging area

  git add [dir]  添加指定目录到staging area

  git add .  添加当前目录下的所有文件到staging area

  

  git status  -s  查看仓库当前的状态,显示有变更的文件

  

  git diff [file]  显示staging area 与 workspace的差异

  git diff --cached [file]  or  git diff --staged [file] 显示 staging area 和上一次commit的差异

  git diff [first-branch]...[second-branch]   显示两次提交之间的差异

  

  git commit -m [message]  提交staging area到 local repository

  git commit [file1] [file2]... -m [message] 提交staging area 指定文件到 local repository

  git commit -a  参数设置修改文件后不需要执行git add命令,直接提交

 

  git reset HEAD^  回退所有内容到上一个版本

  git reset HEAD^^  回退所有内容到上上一个版本

  git reset HEAD^ [file1]   回退file1 文件的版本到上一个版本

  git reset [version]  回退到指定版本

 

  git rm [file1]  将file1文件从staging area和workspace中删除

  git rm -f [file1]  将file1文件强制从staging area和workspace中删除

  git rm --cached [file1]  将file1文件从staging area中删除

  

  git mv [file] [newfile]  将file文件内容移动到newfile文件中(新文件不存在)

  git mv -f  [file] [newfile]  将file文件内容移动到newfile文件中(新文件已存在)

 

  提交日志

  git log  查看历史提交记录

  git blame [选项] [文件路径]  以列表形式查看指定文件的历史修改记录。 选项

    -L <起始行号>,<结束行号>:只显示指定行号范围内的代码注释。

    -C:对于重命名或拷贝的代码行,也进行代码行溯源。

    -M:对于移动的代码行,也进行代码行溯源。

    -C -C 或 -M -M:对于较多改动的代码行,进行更进一步的溯源。

    --show-stats:显示包含每个作者的行数统计信息。

 

  远程操作

  git remote  列出当前仓库中已配置的远程仓库

  git remote -v  列出当前仓库中已配置的远程仓库,并显示它们的URL

  git remote rename [old_name] [new_name]   将已配置的远程仓库重命名。

  git remote remove [remote_name]  从当前仓库中删除指定的远程仓库。

  git remote set-url [remote_name] [new_url]  修改指定远程仓库的URL。

  git remote show [remote_name]  显示指定远程仓库的详细信息,包括URL和跟踪分支

  git remote add [remote_name] [remote_url]  添加一个新的远程仓库,指定一个远程苍龙的名称和URL, 将其添加到当前仓库中。

 

  git fetch [alias]  远程获取代码库。

  git merge [alias]/[branch]  从远端仓库提取数据并尝试合并到当前分支

 

  git pull origin master:brantest  从远程主机origin master分支拉取代码,与本地brantest分支合并

  git pull origin master  从远程主机origin master分支拉取代码,与本地当前分支合并

  

  git push origin master : master 将本地master分支推送到origin主机的master分支

  git push  -- force origin master 当本地分支与远程分支有差异,强制将本地推送到origin主机的master分支

  git push origin --delete master  删除origin主机上的master分支

 

posted @   Alpha_To_Beta  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
点击右上角即可分享
微信分享提示