網頁

2023/1/6

Git 比較與上一次提交的差異 compare differences with last commit

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:

  1. Open the command line or terminal in the root directory of your local repository.

  2. 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.

  3. 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.

  4. To get more details of the difference you can use git diff --stat <last_commit_hash>..HEAD

  5. 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.

沒有留言:

張貼留言