Git Pull与&;Git推送

Git Pull与&;Git推送,git,github,ssh,git-push,git-pull,Git,Github,Ssh,Git Push,Git Pull,它是共享的GIT存储库。许多人在同一个git存储库上工作 这就是为什么我先尝试使用git pull来获取其他更改,然后再尝试添加、提交和推送 我已在本地计算机上尝试了以下命令 $ git pull error: Your local changes to the following files would be overwritten by merge: File Name Please commit your changes or stash them before you can mer

它是共享的GIT存储库。许多人在同一个git存储库上工作

这就是为什么我先尝试使用git pull来获取其他更改,然后再尝试添加、提交和推送

我已在本地计算机上尝试了以下命令

$ git pull
error: Your local changes to the following files would be overwritten by merge:

File Name

Please commit your changes or stash them before you can merge.
Aborting
承诺

$ git commit

no changes added to commit

$ git push
To ssh://git@ab.com:2222/diffusion/SMM/abc.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://git@ab.com:2222/diffusion/SMM/abc.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

如何解决这个问题?

您应该花点时间了解git是如何工作的(好资源[1])。特别是,能够查看整个git历史非常重要,为此使用以下命令或git UI(
gitk
git gui
):

git日志--oneline--graph--all--decoration

简言之,可能:
git pull--rebase
将适合您(如果您没有冲突的更改)


[1] 我最近也有同样的问题。您可能忽略了此文件(
.gitignore
.git/info/exclude
),或者您假定它未更改(
git update index--假定未更改

您可以使用git check ignore-v“File Name”检查文件是否被忽略。
如果
ls“File Name
未返回任何错误,则该文件存在,但git假定该文件未更改。您可以使用
git update index--no assessed unchanged
来假定该文件已更改。

因此,您的问题是,您的工作目录中存在未跟踪的文件,您也尝试提取这些文件

因此,文件
某些文件
在您的工作目录中,但有人将同名文件推送到服务器。当您拉取时,它将用远程存储库中的版本覆盖您的本地文件:
您对以下文件的本地更改将被merge
覆盖

要解决此问题,可以做两件事:

  • 将文件移开,拉出,放置两个版本
  • git-add
    文件,
    git-commit
    它和
    git-pull
    将本地更改与上游合并

另外,请阅读。您需要在提交之前将文件添加到暂存区域。这就是为什么
git commit
告诉您没有要提交的暂存文件。
git commit
只提交您放入暂存区域的文件。

按$git status检查状态,添加并提交新的和修改的文件,然后尝试$git pull origin master@AswathyS确切地说,这会有什么帮助?@AnkitShah在提交之前是否尝试添加?您的git状态是什么?@AnkitShah是否列出了未跟踪的文件?@AnkitShah您不了解哪些部分?您有本地更改。拉操作会与这些更改冲突。您必须提交或还原这些更改。如果您希望提交这些更改,请我们必须先添加它们(因此“使用”git add…“将其包含在将提交的内容中”)。是的,我们有
.gitignore
文件