我想推送我的本地文件,并将它们放在远程仓库上,而不必处理合并冲突.我只是希望我的本地版本优先于远程版本.
我怎么能用Git做到这一点?
我希望在我的项目的第一次提交中更改某些内容而不会丢失所有后续提交.有没有办法做到这一点?
我不小心在源代码中的评论中列出了我的原始电子邮件,我想改变它,因为我从机器人索引GitHub收到垃圾邮件.
我想在GitHub上放置一个Git项目,但它包含某些带有敏感数据的文件(用户名和密码,比如/ config/deploy.rb for capistrano).
我知道我可以将这些文件名添加到.gitignore,但这不会删除他们在Git中的历史记录.
我也不想通过删除/.git目录重新开始.
有没有办法删除Git历史记录中特定文件的所有痕迹?
有办法从以后的提交中更改消息:
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
Run Code Online (Sandbox Code Playgroud)
如何更改第一次提交(没有父级)的提交消息?
我有一个文件,foo.txt包含以下行:
a
b
c
Run Code Online (Sandbox Code Playgroud)
我想要一个简单的命令,导致内容为foo.txt:
a
b
Run Code Online (Sandbox Code Playgroud) 我有一个名为my_pcc_branch.patch的补丁.
当我尝试应用它时,我得到以下消息:
$ git apply --check my_pcc_branch.patch
warning: src/main/java/.../AbstractedPanel.java has type 100644, expected 100755
error: patch failed: src/main/java/.../AbstractedPanel.java:13
error: src/main/java/.../AbstractedPanel.java: patch does not apply
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
我该如何解决这个问题?
If I have a commit in the past that points to one parent, but I want to change the parent that it points to, how would I go about doing that?
我试图弄清楚Git中的"移植物"是什么.
例如,在这里的一个最新评论中,Tobu假设使用git-filter-branch和.git/info/grafts来连接两个存储库.
但我不明白为什么我需要这些移植物?似乎所有工作都没有最后两个命令.
在另一个问题上使用Chris的答案,我可以将快照历史记录添加到我的git存储库中.由于其中一个文件不是我的历史记录的一部分,而只是在快照中,因此第一个原始提交现在也包含此文件的删除.我该怎么撤消?
起初我认为这与我如何从git的历史记录中删除敏感文件相反,但实际上我不想将文件插入历史记录,只是从历史记录中删除删除.
当我使用时git format-patch,它似乎不包括合并.如何执行合并,然后将其作为一组补丁通过电子邮件发送给某人?
例如,假设我合并了两个分支并在合并之上执行另一个提交:
git init
echo "initial file" > test.txt
git add test.txt
git commit -m "Commit A"
git checkout -b foo master
echo "foo" > test.txt
git commit -a -m "Commit B"
git checkout -b bar master
echo "bar" > test.txt
git commit -a -m "Commit C"
git merge foo
echo "foobar" > test.txt
git commit -a -m "Commit M"
echo "2nd line" >> test.txt
git commit -a -m "Commit D"
Run Code Online (Sandbox Code Playgroud)
这将创建以下树:
B
/ \
A M …Run Code Online (Sandbox Code Playgroud) git ×9
git-commit ×2
bash ×1
command-line ×1
git-amend ×1
git-push ×1
git-rebase ×1
history ×1
merge ×1
msysgit ×1
patch ×1
rebase ×1
repository ×1
scripting ×1
truncate ×1
undelete ×1