在git中,是否有任何(简单)方法来修改索引,以便只添加已经存在于其中的文件的更改?这听起来有点复杂,但我想要实现的很简单.
让我们说我的索引看起来像这样(稍微剥离git status输出):
# Changes to be committed:
# modified: A
# modified: B
#
# Changed but not updated:
# modified: B
# modified: C
#
# Untracked files:
# D
Run Code Online (Sandbox Code Playgroud)
B索引中有一些变化,有些变化不是.
C根本没有上演.
如何B在不添加的情况下更新索引(暂存其未分级的更改)C?
即我希望索引看起来像这样:
# Changes to be committed:
# modified: A
# modified: B
#
# Changed but not updated:
# modified: C
#
# Untracked files:
# D
Run Code Online (Sandbox Code Playgroud)
在这个简单的情况下,它当然可以用一个简单的方法实现git add B,但我想知道是否有一个简单的答案.我试过git add --refresh,但如果我理解正确,那只会更新统计信息.
我想使用Git的耐心差异算法(如果你git diff用--patience参数调用你得到的算法)git add -p.我怎样才能做到这一点?
背景:我正在使用一些XML文件,并且由于"未对齐"的进入/退出标记,git diff正常算法会产生相当差的差异.如果我运行git diff --patience,我会得到更多有用的差异,但没有明显的方法来使用这些差异git add -p.
好的,所以当我遇到" 从已从磁盘中删除的Git仓库中删除多个文件 "时,我正在搜索"如何从Git中删除手动删除的文件"而不实际git rm file.txt为每个文件执行操作.
两个最受欢迎的命令是:
git add -ugit add -A虽然它们都适合我,但我仍然无法理解其中的差异,并且页面上的解决方案也没有解释.我的问题是,它们如何彼此不同,以及可以使用哪些其他git命令来删除从磁盘手动删除的文件?
我有一个文件,我已重命名,然后编辑.我想告诉Git进行重命名,但不是内容修改.也就是说,我希望删除旧文件名,并添加旧文件内容和新文件名.
所以我有这个:
Changes not staged for commit:
deleted: old-name.txt
Untracked files:
new-name.txt
Run Code Online (Sandbox Code Playgroud)
但想要这个:
Changes to be committed:
new file: new-name.txt
deleted: old-name.txt
Changes not staged for commit:
modified: new-name.txt
Run Code Online (Sandbox Code Playgroud)
或这个:
Changes to be committed:
renamed: old-name.txt -> new-name.txt
Changes not staged for commit:
modified: new-name.txt
Run Code Online (Sandbox Code Playgroud)
(相似性度量应为100%).
我想不出一个直截了当的方法来做到这一点.
是否有获取特定文件的特定修订内容的语法,并将其添加到指定路径下的git临时区域?
删除部分,git rm很好:
$ git rm old-name.txt
Run Code Online (Sandbox Code Playgroud)
这是我正在努力的重命名的补充部分.(我可以保存新内容,mv在shell中签出一份新的副本(旧内容),git add然后恢复新内容,但这似乎有很长的路要走!)
谢谢!
git diff认为没有变化..即使git status报告他们被修改了?
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: file-added
modified: file-with-changes << it knows there are changes
Run Code Online (Sandbox Code Playgroud)
但为了看到差异,我需要显式添加最后一个reversion哈希..
$ git diff
(nothing)
$ git diff rev-hash
diff --git a/file-with-changes b/file-with-changes
index d251979..a5fff1c 100644
--- a/file-with-changes
+++ b/file-with-changes
.
..
Run Code Online (Sandbox Code Playgroud) 我有一个巨大的补丁,我想打破多个逻辑git提交.大量的更改只是更改变量名称或函数调用,以便可以使用grep轻松定位它们.如果我可以向索引添加任何与正则表达式相匹配的更改然后在git gui中清理,它将为我节省大量的手动工作.是否有一种很好的方法可以在git中使用正则表达式或从grep的某些输出(例如行号)逐行更新索引?
我发现了一个类似的问题,但我不确定如何从正则表达式搜索构建临时文件.
我想在给定存储库的克隆中始终存在一些钩子.有没有办法在存储库中的.git/hooks中添加文件?
谢谢
不知道为什么会这样:
git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: file (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
starkers@ubuntu:~/Documents/currentWork/protection_demo$ git add --all
starkers@ubuntu:~/Documents/currentWork/protection_demo$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what …Run Code Online (Sandbox Code Playgroud) 从这段摘录中可以看出,有一个"!" 在git命令之前.重点是什么?
[alias]
commitx = !git add . && git commit
Run Code Online (Sandbox Code Playgroud)
我理解别名和命令本身正在做什么,但不是"!"的意思.在git命令之前.
git ×10
git-add ×10
git-diff ×2
file-rename ×1
git-alias ×1
git-commands ×1
git-patch ×1
githooks ×1
regex ×1
terminal ×1