Git與上一次提交比較差異的方式如下。
使用以下命令皆可比較目前檔案與上一次提交的差異。
git diff HEAD^ HEAD
。
$ git diff HEAD^ HEAD
或git diff @~..@
。
$ git diff @~..@
或git show
。
$ git show
若只要檔案差異可加上--name-only
參數。
$ git diff --name-only HEAD^ HEAD
Question
how to compare current commit with last commit in Git
ChatGPT
In Git, you can compare the current commit with the last commit using the git diff command. Here's how you can use it:
Open the command line or terminal in the root directory of your local repository.
Use the command git diff HEAD^..HEAD or git diff HEAD~1..HEAD to compare the current commit with the last commit.
This command compares the last two commits in the current branch, the current commit and the last one.
Alternatively, you can use git diff <last_commit_hash>..HEAD where last_commit_hash is the hash of the last commit. This command compare current commit with a specific commit.
To get more details of the difference you can use git diff --stat <last_commit_hash>..HEAD
Additionally, you can use Git UI clients like GitKraken, SourceTree or Git extension for VSCode for a more visual comparison of the commits.
Note that, the commands shown here are for comparing commits in the current branch. If you want to compare commits across branches, you will need to specify the branch names or commit hashes.
沒有留言:
張貼留言