You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 22012f9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.org
+70-9Lines changed: 70 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,30 @@
5
5
6
6
This is a small tool that helps to list the files you have changed (added/modified/removed) in your git branch.
7
7
8
-
This can be useful when working with large repositories, as you can run tools on a specific subset of files instead of the entire repository.
9
-
It can be easily integrated into your workflow to streamline your development process.
8
+
** Motivation
9
+
10
+
The author wrote this tool for a project with very slow tests and tools. A full run took too long for each small change. The author wanted to run the tests and tools only on the files of the current branch.
11
+
12
+
The tool lists these files:
13
+
14
+
- the files from the commits since the branch left ~origin/main~
15
+
- the files with uncommitted changes
16
+
- the untracked files
17
+
18
+
The tool only prints the list. Send the list to another tool:
19
+
20
+
#+begin_src bash
21
+
$ git-changed -e '**/*.rs' | xargs rustfmt
22
+
#+end_src
23
+
24
+
** Alternatives
25
+
26
+
- ~git diff --name-only $(git merge-base origin/main HEAD)~ lists the committed and the uncommitted changes. It does not list the untracked files. Add ~git ls-files --others --exclude-standard~ for those.
27
+
- lint-staged (https://github.com/lint-staged/lint-staged) runs commands on the staged files before a commit. It needs Node.js.
28
+
- lefthook (https://github.com/evilmartians/lefthook) is a git hook manager. It gives ~{staged_files}~ and ~{push_files}~ to the commands. A ~lefthook~ command can also call ~git-changed~.
29
+
- tj-actions/changed-files (https://github.com/tj-actions/changed-files) lists the changed files in GitHub Actions.
30
+
31
+
~git-changed~ does not run commands and does not manage hooks. It only lists the files, so you can use it in a terminal, in a hook, or in CI.
Per default the script uses the ~init.defaultBranch~ if that is configured, and falls back to ~main~, you can override this setting by a command line parameter:
80
+
The tool compares your branch with ~origin/main~. It does not use your local ~main~ branch, because that branch can be old.
81
+
82
+
To use a different base, give the ~--base~ option:
59
83
60
84
#+begin_src bash
61
85
$ git-changed --base development
@@ -73,11 +97,7 @@ Or only for the current repository:
73
97
$ git config changed.defaultBranch development
74
98
#+end_src
75
99
76
-
The value can be any revision. If your local ~main~ is older than the remote one, the tool also lists the files that changed on ~main~ after your local copy. To compare with the remote branch, set:
77
-
78
-
#+begin_src bash
79
-
$ git config changed.defaultBranch origin/main
80
-
#+end_src
100
+
The value can be any revision, for example a branch, a tag, or ~upstream/main~.
81
101
82
102
*** Filtering files with glob pattern
83
103
@@ -101,7 +121,48 @@ Some tools may not handle files that no longer exist. With this option, you can
101
121
$ git-changed -e
102
122
#+end_src
103
123
104
-
*** A more complex example
124
+
*** Examples
125
+
126
+
Run only the specs of the branch. A new spec file is in the list before you run ~git add~:
Run the tests again each time that you save a changed file. entr (https://github.com/eradman/entr) reads the list of files to watch from standard input:
139
+
140
+
#+begin_src bash
141
+
$ git-changed -e '**/*.rs' | entr -c cargo test
142
+
#+end_src
143
+
144
+
Open all changed files in the editor:
145
+
146
+
#+begin_src bash
147
+
$ vim $(git-changed -e)
148
+
#+end_src
149
+
150
+
Select one changed file with fzf (https://github.com/junegunn/fzf) and open it:
151
+
152
+
#+begin_src bash
153
+
$ vim "$(git-changed -e | fzf)"
154
+
#+end_src
155
+
156
+
Run a linter before each push with lefthook. The list contains all the work on the branch, also the work that you did not commit:
0 commit comments