Git 기록에서 빠르게 가져오기

문제를 해결하는 동안 내 동료는 우리 응용 프로그램의 이전 버전에 사용할 수 있는 구문 예제가 있다는 것을 기억했습니다. 고맙게도 코드베이스가 체크인되었습니다 git ! 문제의 코드가 mkDerivation nix 기능을 중심으로 회전한다는 것을 알고 있었습니다.

그 이후로 이 특정 코드는 코드베이스에서 벗어나 nixpkgs 에 추가되었으므로 자체 트리 외부 논리를 정의하는 대신 기본 트리에서 파생물을 가져올 수 있습니다. 나의 첫 번째 본능은 파일을 찾아 참조로 사용하기 위해 그 (거대한) 저장소를 파헤치기 시작하는 것이었습니다.

필요 없음! 우리 git 역사에 있습니다. git log -S를 사용하여 쿼리할 수 있습니다.

$ git log -S mkDerivation
commit 3a275488e740ae1b4314208a908c5300f9563ee0
Author: David Yamnitsky <[email protected]>
Date:   Mon Jul 19 11:51:47 2021 -0400

    use mold and wasm-bindgen from nixpkgs

commit a3a042b5b90ad57ff11bc47a5db6e68dc1ca55e7
Author: David Yamnitsky <[email protected]>
Date:   Wed Jun 16 10:26:35 2021 -0400

    use mold as the linker to speed up incremental compiles on x86_64-linux


아름답다 - 이 파생물을 nixpkgs 에서 직접 가져오도록 전환했을 때 상위 커밋이 나타내는 것처럼 보입니다. 코드를 제거하는 것으로 충분합니다. 각 git 커밋은 diff를 나타냅니다. 이 커밋은 다음 코드를 보여줘야 합니다.

$ git show 3a275488e740ae1b4314208a908c5300f9563ee0
commit 3a275488e740ae1b4314208a908c5300f9563ee0
Author: David Yamnitsky <[email protected]>
Date:   Mon Jul 19 11:51:47 2021 -0400

    use mold and wasm-bindgen from nixpkgs
...
flake. nix

───┐
1: │
───┘
{
  inputs = {
    nixpkgs = {
      url = "github:nixos/nixpkgs/nixos-unstable";
      url = "github:nixos/nixpkgs/nixos-unstable-small";
    };
    flake-utils = {
      url = "github:numtide/flake-utils";

────┐
48: │
────┘
        CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = toString ./. + "/scripts/clang";
        CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld";
        buildInputs = with pkgs; [
          (stdenv.mkDerivation {
            pname = "mold";
            version = "0.9.1";
            src = fetchgit {
              url = "https://github.com/rui314/mold";
              rev = "v0.9.1";
              sha256 = "sha256-yIkW6OCXhlHZ1jC8/yMAdJbSgY9K40POT2zWv6wYr5E=";
            };
            nativeBuildInputs = [ clang_12 cmake lld_12 tbb xxHash zlib openssl git ];
            dontUseCmakeConfigure = "true";
            buildPhase = "make -j $NIX_BUILD_CORES";
            installPhase = "mkdir -p $out $out/bin $out/share/man/man1 && PREFIX=$out make install";
          })
          cachix
          cargo-insta
          clang_12



텍스트에 있습니다! 내 터미널에서 추가는 녹색으로 강조 표시되고 제거는 빨간색으로 강조 표시됩니다. 이것은 제거되었지만 여전히 제거된 전체 텍스트를 얻을 수 있습니다. 그 stdenv.mkDerivation 코드를 복사하고 거기에서 작업할 수 있었습니다. 감사합니다. git . (티).

제쳐두고 다음git 별칭을 적극 권장합니다.

l = "log --all --graph --decorate --abbrev-commit --format=format:'%C(bold blue)%h%C(reset) - %C(bold white)%an%C(reset) %C(bold yellow)%d%C(reset)%n%C(bold cyan)%aD%C(reset) - %C(bold green)(%ar)%C(reset)%n%C(white)%s%C(reset)'";


텍스트가 엉망이지만 git 기록을 읽기가 매우 쉽습니다.

* 9b24232 - Ben Lovy  (HEAD -> main, origin/main, origin/HEAD)
| Fri, 22 Oct 2021 11:49:42 -0400 - (8 hours ago)
| Remove maplit
* 65016b6 - David Yamnitsky 
| Fri, 22 Oct 2021 11:39:12 -0400 - (8 hours ago)
| update deps
| * 6d55d3e - Ben Lovy  (refs/stash)
|/| Fri, 22 Oct 2021 11:49:01 -0400 - (8 hours ago)
| | WIP on main: e07e691 clear 1.56 warnings
| * 6bf8ab1 - Ben Lovy 
|/  Fri, 22 Oct 2021 11:49:01 -0400 - (8 hours ago)
|   index on main: e07e691 clear 1.56 warnings
* e07e691 - David Yamnitsky 
| Fri, 22 Oct 2021 11:09:02 -0400 - (8 hours ago)
| clear 1.56 warnings


착색은 여기에 반영되지 않습니다. 터미널에서는 더 시원할 것입니다. git 초보자로서 이러한 종류의 출력은 코드베이스의 변경 사항을 추적하는 데 유용합니다.

좋은 웹페이지 즐겨찾기