git命令、gitee代码下载与上传
一、git命令
1. 配置工具
为所有本地存储库配置用户信息
设置要关联到提交事务的名称和邮箱
$ git config --global user.name "[name]" $ git config --global user.email "[email address]"
启用命令行有用的着色
$ git config --global color.ui auto
2. 创建存储库
启动一个新存储库或从现有 URL 获取一个
$ git init [project-name] #Creates a new local repository with the specified name $ git clone [url] #Downloads a project and its entire version history
3. 做出改变
查看编辑并制作提交事务
$ git status #Lists all new or modified files to be committed $ git add [file] #Snapshots the file in preparation for versioning $ git reset [file] #Unstages the file, but preserve its contents $ git diff #Shows file differences not yet staged $ git diff --staged #Shows file differences between staging and the last file version $ git commit -m "[descriptive message]" #Records file snapshots permanently in version history
4. 组变动
命名一系列提交并结合已完成的工作
$ git branch #Lists all local branches in the current repository $ git branch [branch-name] #Creates a new branch $ git checkout [branch-name] #Switches to the specified branch and updates the working directory $ git merge [branch] #Combines the specified branch’s history into the current branch $ git branch -d [branch-name] #Deletes the specified branch
5. 重构文件名
重新定位和删除版本化文件
$ git rm [file] #Deletes the file from the working directory and stages the deletion $ git rm --cached [file] #Removes the file from version control but preserves the file locally $ git mv [file-original] [file-renamed] #Changes the file name and prepares it for commit
6. 同步更改
注册存储库书签并交换版本历史记录
$ git fetch [bookmark] #Downloads all history from the repository bookmark $ git merge [bookmark]/[branch] #Combines bookmark’s branch into current local branch $ git push [alias] [branch] #Uploads all local branch commits to GitHub $ git pull #Downloads bookmark history and incorporates changes
7. 禁止跟踪
排除临时文件和路径
$ git ls-files --other --ignored --exclude-standard #Lists all ignored files in this project
8. 保存片段
搁置和恢复不完整的更改
$ git stash #Temporarily stores all modified tracked files $ git stash list #Lists all stashed changesets $ git stash pop #Restores the most recently stashed files $ git stash drop #Discards the most recently stashed changeset
9. 查看历史
浏览和检查项目文件的演变
$ git log #Lists version history for the current branch $ git log --follow [file] #Lists version history for a file, including renames $ git diff [first-branch]...[second-branch] #Shows content differences between two branches $ git show [commit] #Outputs metadata and content changes of the specified commit
10. 重做提交
擦除错误并制作更换历史
$ git reset [commit] #Undoes all commits after [commit], preserving changes locally $ git reset --hard [commit] #Discards all history and changes back to the specified commit
二、gitee上代码下载与上传
1. 克隆仓库到本地
在克隆/下载的复制SSH里的git链接
在桌面右击,选择Git Bash Here,
使用命令git clone +复制的链接
克隆成功,可在桌面看到相关文件
2. 关联本地工程到远程仓库
在本地库上使用命令 git remote add把它和 gitee 的远程库关联,如下
git remote add origin git@gitee.com:username/test1.git
如果在使用命令 git remote add时报错:
git remote add origin git@gitee.com:username/test1.git fatal: remote origin already exists.
说明本地库已经关联了一个名叫 origin的远程库,此时,可以先用git remote -v查看远程库信息:
git remote -v origin git@gitee.com:username/test1.git (fetch) origin git@gitee.com:username/test1.git (push)
可以删除已有的远程库
git remote rm origin
再关联远程库
git remote add origin git@gitee.com:username/test1.git
3. 上传文件
在本地添加test_pushFile.txt文件,
打开git,执行git的add、commit、push命令,即可将本地文件上传到远程仓库。进入工程文件,添加并提交事务:
push到远程仓库
刷新gitee网页,看见文件成功上传了。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战