git——命令备份

# 克隆代码
344
git clone http://xc@11.9.9.9:10001/r/cocos/hi-ex.git 345 git status 346 cd hi-ex/ 347 git status 348 git add * 349 git commit -m "[hi-ex]init proj ..."354 git push 356 git status
# 创建分支
357 git branch alpha 358 git branch
360 git branch -a

# 切换分支
361 git checkout alpha 362 git status 363 git branch 364 git branch -a 365 git checkout -h 366 git branch -h
370 git branch -l

# 首次把分支推到远端 373 git push -u origin alpha 374 history

# 重定向

   git branch -la
   git remote show origin
   git remote set-url origin https://gitee.com/xingchong/SPTools.git
   git remote -v
   git remote show origin

 

一、pull操作

1、将远程指定分支 拉取到 本地指定分支上:
git pull origin <远程分支名>:<本地分支名>

2、将远程指定分支 拉取到 本地当前分支上:
git pull origin <远程分支名>

3、将与本地当前分支同名的远程分支 拉取到 本地当前分支上(需先关联远程分支,方法见文章末尾)
git pull
在克隆远程项目的时候,本地分支会自动与远程仓库建立追踪关系,可以使用默认的origin来替代远程仓库名,
所以,我常用的命令就是 git pull origin <远程分支名>,操作简单,安全可控。


二、push操作

1、将本地当前分支 推送到 远程指定分支上(注意:pull是远程在前本地在后,push相反):
git push origin <本地分支名>:<远程分支名>

2、将本地当前分支 推送到 与本地当前分支同名的远程分支上(注意:pull是远程在前本地在后,push相反):
git push origin <本地分支名>

3、将本地当前分支 推送到 与本地当前分支同名的远程分支上(需先关联远程分支,方法见文章末尾)
git push
同样的,推荐使用第2种方式,git push origin <远程同名分支名>

 

4、将本地分支与远程同名分支相关联

git push --set-upstream origin <本地分支名>

 

5、

在 Git 中,如果你需要撤销对远程 master 分支的 push 操作,可以按照以下步骤进行操作:

  1. 使用 git log 命令查找你要撤销的 push 操作所对应的提交(commit)的哈希值。例如,假设你要撤销最近一次 push 操作,可以使用以下命令查看提交历史:
git log
  1. 找到你要撤销的提交(commit)的哈希值,记下来备用。

  2. 使用 git reset 命令将本地 master 分支的指针重置到你要撤销的提交(commit)的前一个提交(commit)。例如,假设你要撤销最近一次 push 操作,可以使用以下命令:

git reset --hard HEAD^

这将把本地 master 分支的指针重置到当前提交(commit)的前一个提交(commit)。

  1. 使用 git push 命令将本地的重置操作推送到远程 master 分支。例如,可以使用以下命令:
git push -f origin master

使用 -f 参数强制推送,因为我们修改了历史提交(commit)记录,需要覆盖远程仓库的提交记录。

请注意,使用 git resetgit push -f 命令可以修改 Git 仓库的提交历史,因此在执行这些操作之前,请确保你了解其潜在的风险,并在操作前进行备份。同时,如果你的远程仓库是多人共享的,请与团队成员协商和确认,以避免对团队的其他成员造成不必要的困扰。

 
posted @ 2023-02-22 16:06  会飞的斧头  阅读(170)  评论(0编辑  收藏  举报