I believe the two functions below is the same. But AI keep telling me they are different (that I think AI is wrong).
get_changed_files() {
local staged_files committed_files
staged_files=$(git diff --cached --name-only)
committed_files=$(git diff --name-only "1ドル"..HEAD)
# Combine and deduplicate files
printf "%s\n%s\n" "$staged_files" "$committed_files" | sort -u | grep -v '^$'
}
get_changed_files() {
git diff --name-only "1ドル" --cached
}
To be safe, I'm checking here, to see if I miss anything.
1 Answer 1
After some further thought, technically they are the same. However, in detail, there some slight nuances diff.
Case as below
Action 1
- Add and Commit Change to ABC
Action 2
- Revert Commit Change to ABC, and Add (but not commit)
Then
- `git diff --cached --name-only` will return ABC
- `git diff --name-only "1ドル"..HEAD` will return ABC
- This means `get_changed_file()` will return ABC, even thought technically the line change is 0.
However
- `git diff --name-only "1ドル" --cached` will not return anything
- because Action 2 has reverted Action 1.
Hence, there's some slight different here, even though overall, if we want to just count the combined line change, both will be the same.
staged_filesand/orcommitted_files(first function), but not in the comparison between the index and1ドル(second function) ?