相关疑难解决方法(0)

只收藏Git中没有上演的变化

我想做以下工作流程:

  1. 向舞台添加更改.
  2. 存储所有未暂存的其他更改.
  3. 在阶段做一些事情(即构建,运行测试等)
  4. 应用藏匿处.

有没有办法做第2步?

 echo "123" > foo
 git add foo # Assumes this is a git directory
 echo "456" >> foo
 git stash
 cat foo # Should yield 123
Run Code Online (Sandbox Code Playgroud)

git git-stash

193
推荐指数
9
解决办法
4万
查看次数

当计算忽略时,可以让 git 忽略嵌套的 .gitignore 文件吗?

我想将一些被一堆 repos 忽略的文件跟踪到一个 repo 中。

这是一个示例布局:

.
+-- .git
+-- .idea
|-- .gitignore
|-- proj1
|   +-- .git
|   |-- .gitignore
|   |-- foo
|   |   |-- foo.iml
|   |-- bar.c
|   |-- proj1.iml
|-- proj2
    +-- .git
    |-- .gitignore
    +-- bar
    |-- foo.c
    |-- proj2.iml
Run Code Online (Sandbox Code Playgroud)

我想要:

  • 包含所有 *.iml 文件的根级存储库,而每个子存储库单独忽略它们
  • 所有 repos 都是独立的(项目不依赖于根,可以单独操作)
  • 要维护此文件夹结构

有什么解决办法吗?

git gitignore

5
推荐指数
1
解决办法
774
查看次数

Git直接修改索引的内容,用于预提交格式化挂钩

我想在将文件添加到Git索引之前自动格式化我的文件.现在,我有一个预提交钩子,看起来像这样:

#!/bin/bash

set -e
exec 1>&2

workingext="working.$$"
ext="bak.$$"
git diff -z --cached --name-only | egrep -z '\.(pl|pm|t)$' | \
        while read -d'' -r f; do
    # First modify the file in the index
    mv "$f" "$f.$workingext"
    git show :"$f" > "$f"
    perl -c "$f"
    perltidy -pbp -nst -b -bext="$ext" "$f";
    rm -f "$f.$ext"
    git add "$f"
    mv "$f.$workingext" "$f"
    # Then the working copy
    perl -c "$f"
    perltidy -pbp -nst -b -bext="$ext" "$f";
    rm -f "$f.$ext"
done
Run Code Online (Sandbox Code Playgroud)

基本上,我备份工作副本,检查索引副本,格式化它们,将它们添加到索引,然后还原工作副本并格式化它们,以便工作副本和索引副本之间的差异也不会增长大.我首先检查文件的语法,perl -c …

git code-formatting githooks

3
推荐指数
1
解决办法
1144
查看次数

标签 统计

git ×3

code-formatting ×1

git-stash ×1

githooks ×1

gitignore ×1