简体   繁体   English

从远程回购中提取,没有提交历史?

[英]Pull from remote repo without a commit history?

I am working on a project on a gitHub with my friends, and I want to know if there is any way we can pull (update) our local repo without a "pulling commit"? 我正在和朋友们一起在gitHub上进行项目开发,我想知道是否有任何方法可以在不进行“拉入提交”的情况下拉出(更新)本地存储库?

Here is the simplified example of the story: 这是故事的简化示例:

My friend and I had the same copy of the source code from remote repo on our local repo. 我和我的朋友在我们的本地存储库中有来自远程存储库的源代码的相同副本。

Example Source code: 示例源代码:

<p> This is the title </p>
<p> I love to code </p>

Now my friend decided to add another line of code to the original one: 现在,我的朋友决定在原始代码中添加另一行代码:

<p> Adding important text </p>

He then committed and pushed to the remote repo. 然后,他提交并推送到远程仓库。 After that, I pulled from the remote repo. 之后,我从远程仓库中退出。 Now I also have what my friend added. 现在我也有我朋友添加的内容。

Then my friend decided to remove that line of code : 然后我的朋友决定删除该行代码:

<p> Adding important text </p>

Now I have to pull (update) again, but the thing is, because my local has that Added line of code, I am required to make a commit (Merge). 现在,我不得不再次拉(更新),但是问题是,因为我的本地计算机具有那行添加的代码,所以我需要进行一次提交(合并)。 Then when I push, that commit is going to be there. 然后,当我推送时,该提交将在那里。 This means that there are 2 commits with the same change (my friend's commit and my commit's --with different messages, of course) 这意味着有2个提交具有相同的更改(当然,我朋友的提交和我的提交-带有不同的消息)

My question is, is there a better way to deal with this problem? 我的问题是,有没有更好的方法来解决这个问题? Is there a way to avoid unnecessary commits? 有办法避免不必要的提交吗? I know we should wait until we really sure about the changes before we push to the remote, but things happen. 我知道我们应该等到真正确定更改后再推送到遥控器,但是事情确实发生了。

If you would like to clean up the commit history, you can use git reset --hard . 如果您想清除提交历史记录,可以使用git reset --hard

For example, here is your commit history: 例如,这是您的提交历史记录:

commit N+2: "Added important text again"
commit N+1: "Removed important text"
commit N:   "Added important text"
...

You would like to make it look like this: 您想使它看起来像这样:

commit N: "Added important text"
...

Then do the following (where 2 is a number of commits from the last one): 然后执行以下操作(其中2是最后一次提交的数量):

git reset --hard HEAD~2
git push --force

Be careful: using this combination may lead to code loss and you won't be able to restore it. 注意:使用此组合可能会导致代码丢失,并且您将无法还原它。 By the way, that's all right to have identical changes. 顺便说一句,可以进行相同的更改。 At least you don't risk to lose anything. 至少您不会冒任何损失的风险。

暂无
暂无

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

相关问题 推送到远程仓库而不删除远程历史记录 - pushing to remote repo without removing history in remote Git“强制推送”从新的本地仓库到远程,但保持远程提交历史记录 - Git “force push” from new local repo to remote, but keeping remote commit history 从远程仓库获取最后提交日期而不进行克隆 - Getting the last commit date from a remote repo without cloning 当我将提交推送到远程存储库时,为什么Git会显示本地的“从远程拉出”? - Why does Git show my local “pull from remote” when I push my commit to the remote repo? "无需克隆即可从远程仓库获取最后的提交哈希" - Getting the last commit hash from a remote repo without cloning 从远程Git存储库中提取更改并将我的分支提交到远程仓库 - Pull changes from remote Git repository and commit my branch to the remote repo 用本地存储库替换远程存储库,但保留远程的提交历史记录 - replace remote repository with local repo, but keep commit history of remote 将下载的 repo 的提交添加到原始提交历史并允许拉取请求 - Add commits of downloaded repo to the original commit history and allow pull request 在意外从具有不同提交历史的远程仓库中拉出后访问较旧的 Git 提交 - Access older Git commits after accidentially pulling from remote repo with different commit history 将Git repo克隆到新的repo中 - 没有提交历史记录 - Cloning a Git repo into a new repo - without commit history
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM