简体   繁体   English

git 如何在创建存储库后首次提交

[英]git how to do first commit after creating a repository

I work with git. I created a directory reflections4 and I copied a file in it.我使用 git。我创建了一个目录 reflections4 并在其中复制了一个文件。 After this, I executed git init.在此之后,我执行了 git init。

git log displays 

carlotavina (master #) reflections4 $ git log
fatal: your current branch 'master' does not have any commits yet

git status

carlotavina (master #) reflections4 $ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    lesson_1_reflections.txt 

nothing added to commit but untracked files present (use "git add" to track)

How can I display Initial commit in git status after creating a repository创建存储库后如何在 git 状态中显示初始提交

You have not yet committed anything to the repository, only initialized one. 您还没有向存储库提交任何内容,只进行了初始化。 From the documentation, linked below, init creates an empty repository, and does no population. 从下面链接的文档中,init创建一个空的存储库,并且没有填充。 Some services (github/lab, etc) will initialize the repository with a readme file or similar, which must be committed to be tracked. 某些服务(github / lab等)将使用自述文件或类似文件初始化存储库,必须提交跟踪文件。 Manually running init does not do this. 手动运行init不会这样做。

You must add (commit) something to the empty repo it to see it. 你必须向空的repo添加(提交)一些东西才能看到它。 As such, if you git add lesson_1_reflections.txt and git commit -m "first commit" , you will than have a commit that you are able to look at. 因此,如果您git add lesson_1_reflections.txtgit commit -m "first commit" ,那么您将拥有一个能够查看的提交。

If you are trying to sync with a remote repository (one hosted on another server, github, gitlab, bitbucket, etc.), there are additional steps you will have to take to make the two repositories (local and remote) talk to each other. 如果您尝试与远程存储库(托管在另一台服务器,github,gitlab,bitbucket等上)进行同步,则必须采取其他步骤才能使两个存储库(本地和远程)相互通信。

https://git-scm.com/docs/git-init https://git-scm.com/docs/git-init

Step 1: 第1步:

git add lesson_1_reflections.txt

Step 2: 第2步:

git commit -m "<enter the desired commit message>"

Step 3 (after you set up a remote to push into): 第3步(设置遥控器后推入):

git push

If prompted enter user and password 如果提示输入用户名和密码

https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html Lookout on this webpage you will find every information you want. https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html在此网页上了解您可以找到您想要的所有信息。

In your case, you have to add those files to your repository by 在您的情况下,您必须将这些文件添加到您的存储库中

git add . // . means everything or "all"

git status // now you can see all the changes
git commit -m "Message that you want to send regarding this commit"
git push origin "whatever the branch name"(optional)

When you have empty repo.当你有空回购时。 You can follow these steps for doing initial commit.您可以按照以下步骤进行初始提交。

  1. Clone the empty repo.克隆空回购。 git clone <your git repo url>
  2. Now go to your repo using cd command and create a local branch say developement using command git checkout -b development现在 go 使用cd命令到你的 repo 并使用命令git checkout -b development创建一个本地分支说developement
  3. We can now add some files in the repo echo "A new repo" > Readme我们现在可以在回购中添加一些文件echo "A new repo" > Readme
  4. Stage all the unstages files to commit git add.暂存所有未暂存文件以提交git add.
  5. Show the staged files git status显示暂存文件git status
  6. Commit the files to local git repo git commit -m "Adding readme file"将文件提交到本地 git repo git commit -m "Adding readme file"
  7. Push the commit to your remote repo using git push -u origin development:development使用git push -u origin development:development将提交推送到您的远程仓库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM