[英]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.