Loading... ## 配置相关 ## ```shell git config --list # 查看配置信息 git config --global user.name=xxx # 设置全局用户名 git config --global user.email=xxxx@yyy.com # 设置全局用户邮箱 git remote add [shortname] [url] # 增加一个新的远程仓库,并命名 ``` 相关的配置信息在`.gitconfig`文件中: [user] name = xxx email = xxxx@yyy.com ## 初始化 ## ```shell git init # 在当前目录下初始化一个git仓库 git init [dir] # 将指定目录[dir]初始化为一个git仓库 ``` ## 查询 ## ``` git status # 查询当前git仓库状态信息 git log # log查询 git reflog # reflog查询 git remote -v # 显示所有远程仓库 git remote show [remote] # 显示某个远程仓库的信息 git log --pretty=short --oneline --shortstat --graph # 常用log查询方式 ``` ## clone操作 ## ``` git clone http://192.168.1.94:48080/root/daemon.git # 直接clone代码, # 注意:如果该仓库有多个分支,可以使用git clone --no-checkout 快速clone,不切换master分支但是克隆之后内容为空,之后手动切换分支 ``` ## add操作 ## ```shell git add [filename] # add指定的文件[filename] git add . # add当前目录下的所有文件 ``` ## commit操作 ## ``` git commit -m 'this is your version note' # 将缓存区的内容提交 ``` ## diff操作 ## ``` git diff # 对比所有文件的修改内容 git diff [filename] # 对比指定文件[filename]的修改内容 ``` ## 版本控制 ## ``` git reset --hard [hashcode] # 切换至[hashcode]所指定的版本 ``` ## 分支管理 ## ``` git branch # 查看当前分支 git branch develops # 创建新的develops分支 git checkout develops # 切换分支 git checkout -b feature # 创建以及切换feature 分支 git branch -d slave # 删除slave分支,强制删除用-D git merge slave # 在当前分支下合并slave分支 # 注意:当分支内容冲突时,可以使用git merge [branch_name] --abort(撤销合并,内容不会变化)修改冲突之后进行git commit进行合并 ``` ## 远程同步 ## ``` git fetch [remote] # 下载远程仓库的所有变动 git pull [remote] [branch] # 取回远程仓库的变化,并与本地分支合并 git push [remote] [branch] # 上传本地指定分支到远程仓库 git push [remote] --force # 推送所有分支到远程仓库 git push [remote] --all # 推送所有分支到远程仓库 ``` Last modification:December 2, 2022 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏