LAMMPS from scratch · 20 min
Git: seeing exactly what changed
Git keeps every version of LAMMPS and shows any change as a diff: the lines removed in red, the lines added in green. You learn to read one, then follow a real experiment: one character of the LAMMPS source changed, recompiled, run, matched by hand, and undone.
- The git commands that download a version, show changes and undo them
- How to read a diff, line by line
- A real one-character change to LAMMPS: predict its effect, compare with the run, undo it
1 · Understand: git remembers every version
LAMMPS is developed with git, a program that stores every version of every file. Two uses matter for this course: you download an exact version (so your line numbers match ours), and after you edit the code, git shows exactly what you changed and can undo it. Every code change in Part E will be shown this way.
| Command | What it does |
|---|---|
git clone -b stable_22Jul2025_update6 --depth 1 https://github.com/lammps/lammps.git | download one exact version (page 0.4) |
git status | list the files you have changed |
git diff | show every changed line |
git diff --stat | just count the changes per file |
git restore src/pair_lj_cut.cpp | undo your changes to one file |
git stash / git stash pop | put all changes aside / bring them back |
2 · A real change, read as a diff
We changed one character in src/pair_lj_cut.cpp: the 4.0 in line 511 became 2.0. This is what git reported, copied from our terminal:
| Line of the diff | Meaning |
|---|---|
--- a/…, +++ b/… | a is the file before, b the file after |
@@ -508,7 +508,7 @@ | this piece starts at line 508 and shows 7 lines, before and after |
double PairLJCut::init_one(…) | the function the change is in (a helpful extra) |
| lines starting with a space | unchanged, shown for context |
| − red | removed |
| + green | added: a changed line appears as one removal and one addition |
| "Not currently on any branch" | normal: you downloaded a release tag, not a line of development |
Notice the "Not currently on any branch" line: it is not an error, only a reminder that you are on a fixed release.
3 · Predict by hand, then observe the real run
lj3 is used only in the energy line (page 0.1, line 129). The force lines use lj1 and lj2, which did not change. So before running anything we can predict:
We recompiled (16 s: two files, pair_lj_cut.cpp and lammps.cpp, which records the git state in the version information) and ran melt. Real output, original and changed:
| Step | Temp | E_pair original | E_pair changed | Press (both) |
|---|---|---|---|---|
| 0 | 3 | −6.7733681 | −8.3135355 | −3.7033504 |
| 50 | 1.6842865 | −4.8082494 | −8.4398955 | 5.5666131 |
| 100 | 1.6712577 | −4.7875609 | −8.4401865 | 5.6613913 |
| 150 | 1.6444751 | −4.7471034 | −8.4454307 | 5.8614211 |
| 200 | 1.6471542 | −4.7509053 | −8.4561267 | 5.8805431 |
| 250 | 1.6645597 | −4.7774327 | −8.4536814 | 5.7526089 |
Every prediction holds: step 0 matches to all digits, and Temp and Press are identical at every step. The change made the reported energy wrong without changing the motion at all. That is a warning for Part E: energy and force are written in separate lines, and a code change must keep them consistent (F = −dE/dr), or the program will run happily and print nonsense.
4 · Your own edit: see the diff and the prediction
Change the four numbers of lines 509–512. The page writes the diff git would show, and predicts the melt step-0 line by hand. To run your edit for real you would compile it (page 0.4); the run above shows that such predictions hold.
Your turn
1. Change only lj1 from 48.0 to 24.0. What happens to E_pair, Press and the motion?
2. A diff begins with @@ -116,1 +116,1 @@. What does it tell you?
3. You edited three files and want to start again from the release. Which one command undoes everything?
git restore . (the dot means "everything here"). If you might want the changes later, git stash puts them aside instead, and git stash pop brings them back. Then run make again.