git git提交问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1745464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:21:20  来源:igfitidea点击:

git commit problems

git

提问by deepblue

I just commited my working tree, added to index first, with "$git commit -m 'test'" I saved the stdout-put from this to a file and I see at the top of it that it says

我刚刚提交了我的工作树,首先添加到索引中,使用“$git commit -m 'test'”我将 stdout-put 从这个保存到一个文件中,我在它的顶部看到它说

# On branch master  
# Changed but not updated:  
# (use "git add/rm ..." to update what will be commited)  
# (use "git checkout -- ..." to discard changes in working directory)"  

the problem is that my working tree is not being commited to the repo, and I have a feeling this has something to do with it

问题是我的工作树没有被提交到 repo,我觉得这与它有关

thanks

谢谢

回答by d33tah

Short answer:

简短的回答:

git push -u origin master

git push -u origin master

Longer answer:

更长的答案:

You're most likely trying to push commits to a branch that wasn't created yet - for example, on a newly created Github repository without the README file automatically created. By calling git push -u origin master, you specify both the remote that you need to push to (origin, which is usually the git default) and the branch (master, also default in typical cases). According to the git documentation:

您最有可能尝试将提交推送到尚未创建的分支 - 例如,在没有自动创建 README 文件的新创建的 Github 存储库上。通过调用git push -u origin master,您可以指定需要推送到的远程(origin,通常是 git 默认值)和分支(master,在典型情况下也是默认值)。根据 git 文档:

-u, --set-upstreamFor every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).

-u, --set-upstream对于每个最新或成功推送的分支,添加上游(跟踪)引用,由无参数 git-pull(1) 和其他命令使用。有关更多信息,请参阅 git-config(1) 中的 branch..merge。

This means that after a successful run of this command, from then on you'll be able to just use git pushand git pulland it will default to origin master(with some exceptions).

这意味着在成功运行此命令后,从那时起您将能够只使用git pushandgit pull并且它将默认为origin master(有一些例外)。

回答by Will Robertson

Before you commit a change, you must add it to the index first:

在提交更改之前,您必须先将其添加到索引中:

git add myfile
git commit -m "test"

Alternatively, you can work in a more SVN-like style and commit everything that is changed:

或者,您可以使用更类似于 SVN 的样式并提交所有更改的内容:

git commit -a -m "test"

Or you can just add-and-commit a single file:

或者你可以只添加并提交一个文件:

git commit myfile -m "test"

回答by mlibby

Did you do a git add .before you committed?

git add .在承诺之前做过吗?

It's always wise to do a git statusbefore either git addor git committo see what's changed and staged, as well.

最好先做一个git status之前,git add或者git commit看看发生了什么变化和上演的内容。

It's also very handy to do git diffto see the specific changes you are about to commit.

git diff查看您即将提交的特定更改也非常方便。

Here's what git statusshows if you have added a file and then renamed it.

以下是git status您是否添加了文件然后重命名的内容。

me@home:~$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   foo.txt
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    foo.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   bar.txt

At this point you can just do git add .and then git status will give you more information, perhaps pointing out that you still have a new file and a deleted file calledfoo.txt. To fix this you need to manuallygit rm foo.txtbefore doinggit commit`

此时你可以只做git add .然后git status will give you more information, perhaps pointing out that you still have a new file and a deleted file calledfoo.txt . To fix this you need to manuallygit rm foo.txt before doinggit commit`

In the future if you have files in a git repo that you want to move you should use git mv.

将来,如果您要移动 git 存储库中的文件,则应使用git mv.

回答by Aaron

One other thing to note, git add adds the content of those files to the index at the time when you run it. If you run git add and then change the files, the new changes will not show up in the index.

需要注意的另一件事是, git add 在您运行它时将这些文件的内容添加到索引中。如果您运行 git add 然后更改文件,新的更改将不会显示在索引中。

回答by Tomas Markauskas

If you move files around and use git addafterwards, git only adds the new copy, but doesn't remove the old one:

如果您移动文件并在git add之后使用,git 只会添加新副本,但不会删除旧副本:

$ git status
# On branch master
nothing to commit (working directory clean)
$ mv from to
$ git add .
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   to
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    from
#
$ git commit -m "..."
$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    from
#
no changes added to commit (use "git add" and/or "git commit -a")

To remove the old copies you should also use git rm:

要删除旧副本,您还应该使用git rm

$ git rm from
rm 'from'
$ git commit -m "..."
$ git status
# On branch master
nothing to commit (working directory clean)

But I don't see why it doesn't allow you to commit those changes.

但我不明白为什么它不允许您提交这些更改。

回答by Jed Smith

You really have to read the documentation.

你真的必须阅读文档。

git add yourfile
git commit -m "test"

Or, to commit all changed files --

或者,提交所有更改的文件——

git commit -a -m "test"

回答by oshaiken

Guys I had the same problem with Git.
I am running Cygwin on windows 8.

伙计们,我在使用 Git 时遇到了同样的问题。
我在 Windows 8 上运行 Cygwin。

  1. check if you have the repository that you want to commit to.
  2. check the path
  1. 检查您是否有要提交的存储库。
  2. 检查路径

$ git remote -v# this is how you can see your path

$ git remote -v# 这就是你如何看到你的路径

$ git remote set-url origin [email protected]:username/repos.git# this is how you set new path remotely to push files to the right repository. $ git remote -v# to check if the right path was set.

$ git remote set-url origin [email protected]:username/repos.git# 这是远程设置新路径以将文件推送到正确存储库的方式。 $ git remote -v# 检查是否设置了正确的路径。

  1. $ git add .

  1. $ git 添加。

4.

4.

 $ git push origin master

HOPE THIS HELPS

希望这可以帮助