Skip to content

Instantly share code, notes, and snippets.

@Roger8
Last active December 23, 2021 02:57
Show Gist options
  • Save Roger8/1884be91fd4efbf75210e5575b38af4b to your computer and use it in GitHub Desktop.
Save Roger8/1884be91fd4efbf75210e5575b38af4b to your computer and use it in GitHub Desktop.
git 笔记

git 切换到指定历史版本

git clone https://github.com/longcw/MOTDT.git
cd MOTDT/
git status #查看状态
      # master # 在master分支
git log # 查找历史版本sha值
        #commit e8d96c4319d3525375707b73f70d5ffbbc056945 (HEAD -> oldversion)
        #Merge: 9499c1e 41b29f5
        #Author: longc-ubuntu <[email protected]>
        #Date:   Thu Sep 27 16:01:27 2018 +0800
        #
        #    Merge branch 'master' of github.com:longcw/MOTDT
        #
        #commit 9499c1e7f25b753a077443936351aebdd6100b12
        #Author: longc-ubuntu <[email protected]>
        #Date:   Thu Sep 27 16:00:32 2018 +0800
        #
        #    update for torch 0.4
        #
#(git branch 新分支名 SHA值)
git branch oldversion e8d96c4319d3525375707b73f70d5ffbbc056945
#(git checkout 新分支名)
git checkout oldversion (这里代码已经切换为新分支的历史版本)
git branch --list
      #   master
      # * oldversion

绑定本地文件夹至 github 新repository

cd codefolder/
git init 

git remote add origin https://github.com/xxxxxx.git
git pull origin master # 

git config --global user.email "[email protected]"
git add ./*.py # add files
git commit -m "first coooo"  # 需要账号密码
git push origin master # 上传
@Roger8
Copy link
Author

Roger8 commented Feb 22, 2019

已经克隆github repo到本地后:更新本地修改

git status # 查看状态
#On branch master
#Your branch is up to date with 'origin/master'.
git add ./* # 添加本地修改后需要更新的文件
git commit -m 'add project' # 确认修改并添加说明
git push origin master # 上传修改

@Roger8
Copy link
Author

Roger8 commented Dec 23, 2021

git reflog # 查看所有操作
image
git reset --hard bdea404 # 切换回指定版本

@Roger8
Copy link
Author

Roger8 commented Dec 23, 2021

git pull origin main
出现如下错误
From https://github.com/Roger8/GeoMatch

  • branch main -> FETCH_HEAD

fatal: refusing to merge unrelated histories

添加指令

git pull origin main --allow-unrelated-histories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment