在我的第一次提交时,我无法推送更改,因为我的github中已经具有.gitignore和README.md,与本地有所不同

问题描述 投票:0回答:1

我对git很陌生,我正在自我学习。

我在github中创建了一个存储库,其中有两个文件.gitignore和README.md。

现在我在本地文件夹中有一个角度项目。

我想将我的项目推送到新创建的github存储库。所以我按顺序使用了以下命令-

此后我收到以下错误---

To https://github.com/Arpan619Banerjee/test-git-commands.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Arpan619Banerjee/test-git-commands.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.

我了解我的github存储库中存在的.gitignore和README.md文件与我在本地的文件存在差异,因此我必须先拉出更改,然后将其合并,然后再将其推送。但我尝试这样做我从头开始按顺序执行了以下命令,因为在出​​现错误后我不知道如何继续操作,因此我想在推送之前先拉一下dmerge更改。

然后我收到以下消息。此后我不知道该如何进行-

error: The following untracked working tree files would be overwritten by merge:
        .gitignore
        README.md
Please move or remove them before you merge.
Aborting

我在Google中搜索,得到了这个答案-

The problem is that you are not tracking the files 
locally but identical files are tracked remotely so
 in order to "pull" your system would be forced to 
overwrite the local files which are not version controlled.

Try running

git add * 
git stash
git pull

但是这里本地文件将被覆盖,我不希望这样。我希望推送本地更改。如何在此处解决合并冲突以保留我的本地更改。

通过Vs代码git GUI,我能够合并我的本地更改,但是我想通过cmd来完成。请帮助我。

git github git-commit git-merge-conflict
1个回答
0
投票

一种选择是将存储库重新克隆到一个新文件夹中,进行两个文件中所需的更改,然后提交并推送结果。

git clone https://github.com/Arpan619Banerjee/test-git-commands.git FOLDER
# Make appropriate changes
git add FILES
git commit -m "Commit message"
git push

要使存储方式起作用,您需要确保未跟踪的文件在拉动之前被存储起来(可能用git add -f强制添加它们),并记住在之后应用/弹出存储以“存储”那些更改。

© www.soinside.com 2019 - 2024. All rights reserved.