2

git 更新本地代码

 1 year ago
source link: https://vpsxb.net/3636/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

git 更新本地代码

1. 本地代码未修改,只有master分支,直接更新

  1. git pull

但前提必须是本地的代码没更改过。比如,你提交了代码到 github 后,随后别人也提交代码到 github,然后你需要更新别人提交的代码到你本地,

就可以直接使用该命令。假如你提交代码后再修改过你本地的代码,就会产生冲突,直接使用该命令会失败的。

2. 本地代码有修改,多分支。

  1. //切换到master分支
  2. git checkout master
  3. //更新master分支
  4. git pull
  5. //切换到自己的分支isso
  6. git checkout isso
  7. //把master分支合并到自己分支
  8. git merger master

当有多条分支时,一般都是各人有各自属于自己的分支,然后master是主分支。大家都需要把自己的分支先合到master分支。

所以,如果别人提交且合并了他的代码到master分支,就需要先更新master分支,然后再把别人的代码合并到自己的分支。这仅仅是更新自己本地代码可能出现的一种情况。

3. 本地代码有修改,只有master分支,直接覆盖本地代码

  1. //重置索引和工作目录
  2. git reset --hard//更新代码
  3. git pull

这种属于强制更新自己本地的代码,直接覆盖,本地的任何修改都不会保留。

4.本地代码有修改,直接覆盖远程仓库代码

  1. // 覆盖isso分支
  2. git push --force origin isso// 覆盖主分支
  3. git push --force origin master

这种是更新远程仓库的代码,直接强制把自己本地现在的代码推到远程仓库,会直接把远程仓库的的覆盖掉。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK