我从我的项目中检出了特定的提交,并从那里继续工作,希望在该提交之后的更改会被删除,并且我检出的提交将成为新的头。我提交了新的更改,但我无法推送它们。我对git还很陌生。
我所做的是:
1. git checkout 提交哈希值 2. 编辑项目 3. git commit -m "新更改" 4. git push -u origin master 我收到了:
当我输入git status后,会得到以下结果:
谢谢,Milorad Simic
我所做的是:
1. git checkout 提交哈希值 2. 编辑项目 3. git commit -m "新更改" 4. git push -u origin master 我收到了:
To https://github.com/myusername/project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/miloradsimic/ISA16.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
当我输入git status后,会得到以下结果:
HEAD detached from 506f0ec nothing to commit, working directory clean我在头提交时更改了项目层次结构,所以我想将其恢复到以前的状态。我不想与头部合并。 我这样做(简单易行,但不是专业的方法): 我在一个文件夹中有一个带有更改的项目,未定位在头部。 我下载了头提交到新文件夹中,并将所有文件(除git文件外)从具有更改的文件夹复制到此文件夹中。去掉不必要的文件。添加所有更改、提交并推送。
谢谢,Milorad Simic
master
是你的默认分支
,所以不要删除default
分支。现在你想用dev
分支替换你的master
分支吗? - Sajib Khangit checkout master
,删除文件,git commit -am 'Delete unnecessary files'
,git push origin HEAD
。 - Sajib Khandev分支
合并到master分支
以获取你的新更改。更新的答案。 - Sajib Khan