Use a command like:
git diff file_2.rb
See the git diff documentation for full information on the kinds of things you can get differences for.
Normally, git diff by itself shows all the changes in the whole repository (not just the current directory).
Use a command like:
git diff file_2.rb
See the git diff documentation for full information on the kinds of things you can get differences for.
Normally, git diff by itself shows all the changes in the whole repository (not just the current directory).
Another method (mentioned in this SO answer) will keep the history in the terminal and give you a very deep track record of the file itself:
git log --follow -p -- file
This will show the entire history of the file (including history beyond renames and with diffs for each change).
In other words, if the file named bar was once named foo, then git log -p bar (without the --follow option) will only show the file's history up to the point where it was renamed -- it won't show the file's history when it was known as foo. Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo.
What command can view who changed specific line of a file?
How can I see what has changed in a file before committing to git? - Stack Overflow
git log - View the change history of a file using Git versioning - Stack Overflow
Is there a way to use 'git show' on staged changes?
Videos
Hi, What command can view who changed specific line of a file? thanks
You're looking for
git diff --staged
Depending on your exact situation, there are three useful ways to use git diff:
- Show differences between index and working tree; that is, changes you haven't staged to commit:
git diff [filename]
- Show differences between current commit and index; that is, what you're about to commit (
--stageddoes exactly the same thing, use what you like):
git diff --cached [filename]
- Show differences between current commit and working tree:
git diff HEAD [filename]
git diff works recursively on directories, and if no paths are given, it shows all changes.
Use git-diff:
git diff -- yourfile
This lets Git generate the patches for each log entry:
git log -p -- <filename>
-p in git generates patch text
See git help log for more options โ it can actually do a lot of nice things. :)
To get just the diff for a specific commit, use
git show <revision> -- <filename>
or specify any other revision by identifier.
To browse the changes visually:
gitk -- <filename>
To see changes visually without leaving the console, run:
git blame-log <filename>
However, first ensure blame-log command exists, by at least once running:
# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
{ s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
s~/^(diff|---|\\+\\+\+)/{next} \
s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
/^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
{ if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
echo \"Detected binary file, hence not showing lines-changed.\"
git log --oneline --color=always \"\$1\";
fi ) | less -RX #"
Note that
blame-logis intentionally limited to showing few lines per change-range, for example, to skippackage-lock.jsonfaster.
For a graphical view, use gitk:
gitk [filename]
To follow the file across file renames:
gitk --follow [filename]
For a console view, maybe because you SSH into a head-less server, run:
git blame-log <filename>
However, first ensure blame-log command exists, by at least once running:
# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
{ s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
s~/^(diff|---|\\+\\+\+)/{next} \
s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
/^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
{ if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
echo \"Detected binary file, hence not showing lines-changed.\"
git log --oneline --color=always \"\$1\";
fi ) | less -RX #"
Note that
blame-logis intentionally limited to showing few lines per change-range, for example, to skippackage-lock.jsonfaster.