简体   繁体   English

如何清理新的远程git存储库?

[英]How to clean a new remote git repository?

Well, maybe someone asked this before, excuse me if I ask it again. 好吧,也许有人以前问过这个,请问我再问一次。

I was working my thesis for a long time stored in a directory within Dropbox. 我将论文长期保存在Dropbox的目录中。

Now for the revisions I'm receiving helping from some people, and since all this was generated in LaTeX, a repository in git is a good idea. 现在,对于修订,我得到了一些人的帮助,并且由于所有这些都是在LaTeX中生成的,因此在git中存储是一个好主意。 I have to confess that I'm quite new using it. 我不得不承认我是个新手。

So I opened an account inside Bitbucket for store a remote repository from my project (thesis) and ease the revisions and other changes. 因此,我在Bitbucket内开设了一个帐户,用于存储项目(论文)中的远程存储库,并简化了修订和其他更改。

I tried to follow the instructions for create the repository, but I make a mistake, the step I followed were: 我尝试遵循创建存储库的说明,但是我犯了一个错误,我遵循的步骤是:

$ echo "Aradenatorix Veckhom Vacelaevus" >> contributors.txt
$ git add contributors.txt
$ git commit -m 'Initial commit with contributors'
$ git push -u origin master

I did the first 3 lines, but then I saw it was unnecesary becase they was the instructions for create my first file, commit and push, but I have yet a lot of files from the project. 我做了前三行,但是后来看到它是创建我的第一个文件,提交和推送的说明,这是不必要的,但是项目中还有很多文件。 The right steps are: 正确的步骤是:

cd /path/to/my/repo
git remote add origin https://Aradenatorix@bitbucket.org/Aradenatorix/tesis.git
git push -u origin --all # 
git push -u origin --tags #

The firs one I did before so I have no troubles with that, instead of follow the 4th step from the wrong instructions before, I did the second one from this, but when I tried the third I had an error: 我之前做过的第一个,所以我没有任何麻烦,我没有遵循错误指示之前的第4步,而是从此做了第二个,但是当我尝试第三个时,我遇到了一个错误:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.

However I don't need to add all the content of the directory, only the .tex files and a subdirectory with the attached pictures. 但是,我不需要添加目录的所有内容,只需添加.tex文件和带有图片的子目录。 After explaining the above I have two doubts: 在解释了以上内容之后,我有两个疑问:

  1. I know that I can start git with $ git init but... How to stop it? 我知道我可以使用$ git init来启动git,但是...如何停止它?
  2. How to remove all those files bad loaded to that remote repository? 如何删除所有错误地加载到该远程存储库的文件?

I tried with $ git rm and many options such as --dry-run , --cached , -r and --ignore-unmatched but nothing works yet. 我试着用$ git rm和许多选项,如--dry-run--cached-r--ignore-unmatched ,但没有什么工作呢。

Thanks in advance 提前致谢

Assuming you would have made just a couple of commits. 假设您只进行了两次提交。 You can recreate the commit. 您可以重新创建提交。

git reset HEAD~<number of commits>
rm path/to/unnecessary/file

Add new files which were not previously added (optional): 添加以前未添加的新文件(可选):

git add new/files
git commit

To get the number of commits (which should probably be 1 or 2 in your case), 要获取提交次数(在您的情况下,应该为1或2),

git rev-list HEAD --count

Finally, do a force push. 最后,用力推动。

git push origin master --force

This option should be used only if your repo is not shared with other people and you know what you are doing. 仅当您的回购未与他人共享并且您知道自己在做什么时,才应使用此选项。 You will overwrite the remote. 您将覆盖遥控器。 All you remote changes will be overwritten by the local changes. 您所有的远程更改都将被本地更改覆盖。

As you mentioned, it is a fresh repository and you haven't used version control for your project before. 正如您提到的,它是一个全新的存储库,您之前从未使用过项目的版本控制。 So I think you can go ahead with it. 因此,我认为您可以继续进行。

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

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