将git repo的工作副本替换为.git中的实际回购内容? [英] Replace working copy of git repo with actual contents of repo in .git?

查看:126
本文介绍了将git repo的工作副本替换为.git中的实际回购内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR



什么是git命令强制工作副本的内容成为.git子文件夹中实际存在的回购内容? (如果更改从另一台机器推送到具有工作副本的远程仓库)

LONG STORY



我希望我的公司内部使用perforce的团队转移到git。我想用Git-P4来实现。我想要将一段perforce克隆到一个git仓库,并将其作为一个远程仓库,以便人们克隆它,将更改推送到远程仓库,并且我会定期重新提交远程仓库中所做的更改回到仓库。所以我跟着这个教程



http://answers.perforce.com/articles/KB_Article/Git-P4



归结为这个命令:

  git p4克隆//depot/path.to/folder@all文件夹

这可以,然后在我的客户端机器上执行

  git cloneuser1 @ server:/ home / user1 / path / to / folder

这很好,我做了一个测试文件的编辑,然后执行

  git add test7 
git commit -m'test'
git push

当我尝试将它推回到远程回购时,客户端错误

  git push 
user1 @ server1的密码:
计数对象:5,完成。
使用多达4个线程的增量压缩。
压缩对象:100%(2/2),完成。
写入对象:100%(3/3),273字节,完成。
总计3(增量1),重用1(增量0)
远程:错误:拒绝更新检出分支:refs / heads / master
remote:错误:默认情况下,更新当前分支在非裸仓库中
remote:error:被拒绝,因为它会使索引和工作树不一致
remote:error:与你推送的内容相同,并且需要'git reset - 很难'匹配
remote:error:工作树到HEAD。
remote:错误:
remote:错误:您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为
remote:error:'ignore'或'warn',以允许推入
remote:错误:当前分支;然而,除非你
remote:error:安排它更新它的工作树来匹配你在
remote:error:other方面推送的内容,否则不建议这样做。
remote:error:
remote:error:为了压制此消息并保持默认行为,请将
remote:error:'receive.denyCurrentBranch'配置变量设置为'拒绝'。
到user1 @ server1:/ home / user1 / path / to / folder
! [remote rejected] master - > master(分支目前被检出)
错误:未能将一些文件推送到'user1 @ server1:/ home / user1 / path / to / folder'

这里解释了

在Git中使用receive.denyCurrentBranch有什么后果?



然后我设置

  git config receive.denyCurrentBranch忽略

并再次尝试,git push工作。但回到远程回购这一次,它的工作原理,但当我尝试做git身份时,它会抱怨不同的事情。

  git状态
#在分支主机上
#要提交的更改:
#(使用git reset HEAD< file> ...来取消存储)

#deleted:test7

它告诉我这是因为远程回购中的工作副本与刚推入远程仓库的内容不一样。 git p4 submit和git p4 rebase work他们也抱怨这些未提交的更改

  git p4提交
Perforce签出depot路径//depot/path.to/folder/位于/home/user1/path/to/perforce.folder/
同步p4结帐...
... - 文件上传 - 至今。
应用38f67b9 cym:test 7 from linux
//depot/path.to/folder/test7#1 - 打开后添加
//depot/path.to/folder/test7#1 - 没有任何更改
提交模板不变。无论如何提交? [y] es,[n] o(跳过此补丁)y
更改254654使用1个打开的文件创建。
提交更改254654.
锁定1个文件...
添加//depot/path.to/folder/test7#1
更改254654已提交。
所有提交应用!
执行增量导入到refs / remotes / p4 / master git分支
仓库路径://depot/path.to/folder/automation/
导入目的地:refs / remotes / p4 / master
导入修订版本254654(100%)
您有未被更改的更改。请在重新绑定之前提交它们或使用git存储将它们存储起来。

git p4 rebase
执行增量导入到refs / remotes / p4 / master git branch
Depot paths://depot/path.to/folder/
No更改导入!
您有未得到的改变。请在重新绑定之前提交它们或使用git存储将它们存储起来。

随着时间的推移,这似乎会成为一个大问题。我不希望永久地将工作副本留在远程仓库中。



所以我必须弄清楚如何强制覆盖工作仓库的内容与.git文件夹中的实际存储库索引。



现在我发现这个



如何在Git中放弃未更改的变更?



其中说要做到这一点

  git储存保存--keep-index 
git储存删除

或执行此操作

  git checkout  - 。 

并且其中一个没有工作。他们看起来像他们的工作,但增加的文件仍然不存在,并且git状态仍显示工作副本和索引之间的差异造成的未分级更改。



<$ p $保存工作目录和索引状态在主WIP上:38f67b9 cym:test 7 from linux
HEAD现在在38f67b9 cym:test 7从linux
git stash drop
丢弃的refs / stash @ {0}(3ce5805230e4faa3ec4dd2daa9cb65c86335e1a8)
git status
#分支大师
#要提交的更改:
$(使用git reset HEAD< file> ...来暂停)

#已删除:test7


git checkout - 。

git status
#在分支主机上
#要提交的更改:
#(使用git reset HEAD< file> ...

#已删除:test7

我强制工作副本来表示实际上在回购中的内容?

解决方案

git checkout -f 获取存储库中所有文件的最新版本。 git clean -f 在root中删除所有不受版本控制的文件, git clean -f -x 还会删除显式忽略的文件(位于 .gitignore 文件中)。


TLDR

What is the git command to force the contents of the working copy to be what's actually in the repo in the .git subfolder? (In the event that changes are pushed from another machine to a remote repo that has a working copy)

LONG STORY

I would like my team within my company, which uses perforce, to move to git. I want to use Git-P4 to achieve that. I want to have a section of perforce cloned to a git repo, and make that a remote repo, so that people would clone that, push changes to the remote repo and I would periodically resubmit the changes made in the remote repo back to the perforce. So I followed this tutorial

http://answers.perforce.com/articles/KB_Article/Git-P4

which boiled down to this command:

git p4 clone //depot/path.to/folder@all folder

That works, then on my client machine I do

git clone "user1@server:/home/user1/path/to/folder"

and that's fine and it shows up so I make an edit to a test file, then do the

git add test7
git commit -m 'test'
git push

When I try to push it back to the remote repo, I get this error on the client

git push
user1@server1's password: 
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 273 bytes, done.
Total 3 (delta 1), reused 1 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To user1@server1:/home/user1/path/to/folder
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'user1@server1:/home/user1/path/to/folder'

which is explained here

What are the consequences of using receive.denyCurrentBranch in Git?

so then I set

git config receive.denyCurrentBranch ignore

and tried it again and git push worked. But back at the remote repo this time, it works but it complains about something different when I try to do a git status

git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    test7
#

It's telling me this because the working copy in the remote repo is not the same as what's just been pushed to the remote repo. git p4 submit and git p4 rebase work they also complain about these uncommitted changes

git p4 submit
Perforce checkout for depot path //depot/path.to/folder/ located at /home/user1/path/to/perforce.folder/
Synchronizing p4 checkout...
... - file(s) up-to-date.
Applying 38f67b9 cym: test 7 from linux
//depot/path.to/folder/test7#1 - opened for add
//depot/path.to/folder/test7#1 - nothing changed
Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) y
Change 254654 created with 1 open file(s).
Submitting change 254654.
Locking 1 files ...
add //depot/path.to/folder/test7#1
Change 254654 submitted.
All commits applied!
Performing incremental import into refs/remotes/p4/master git branch
Depot paths: //depot/path.to/folder/automation/
Import destination: refs/remotes/p4/master
Importing revision 254654 (100%)
You have uncommited changes. Please commit them before rebasing or stash them away with git stash.

git p4 rebase
Performing incremental import into refs/remotes/p4/master git branch
Depot paths: //depot/path.to/folder/
No changes to import!
You have uncommited changes. Please commit them before rebasing or stash them away with git stash.

This seems like something that will become a big problem over time. I don't want to leave the working copy on the remote repo in that state permanently.

So I have to figure out how to forcefully overwrite the contents of the working repo with the actual repository's index in the .git folder.

Now I found this

How do I discard unstaged changes in Git?

Which said to do this

git stash save --keep-index
git stash drop

or do this

git checkout -- .

and neither one of those worked. They looked like they worked, but the added file was still not there and git status still showed the unstaged change caused by the difference between the working copy and the index.

git stash save --keep-index
Saved working directory and index state WIP on master: 38f67b9 cym: test 7 from linux
HEAD is now at 38f67b9 cym: test 7 from linux
git stash drop
Dropped refs/stash@{0} (3ce5805230e4faa3ec4dd2daa9cb65c86335e1a8)
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    test7
#

git checkout -- .

git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    test7
#

So how do I force the working copy to represent the contents of the what's actually in the repo?

解决方案

git checkout -f gets the last version of all files in the repository. git clean -f in the root deletes all files that aren't under version control, git clean -f -x also deletes the files that are explicitly ignored (in .gitignore files).

这篇关于将git repo的工作副本替换为.git中的实际回购内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆