Files not updated when commit

Hello,
I'm a beginner in Rust.
When I commit, everything looks normal, no error messages. But the master branch is not updated. I've verified the git add . and git tells me that there is nothing to commit. But when i change the branches I see the differences in the main.rs file.
It only happens in the rust project.
Thanks in advance.

It's really hard to debug this kind of problem solely from a description. Can you copy and paste the text of a terminal session that demonstrates the misbehavior?

3 Likes

I'm using Ubuntu 24.04.1 LTS running WSL in a Windows 11 machine.

After creating the simplest project in Cargo, I follow these steps:

git config --list ==>
user.email= my email
user.name=my user name
core.bare=false
core.repositoryformatversion=0
core.filemode=true
core.logallrefupdates=true


This is the initial code

fn main() {
    println!("Hello, world!");
}```

---------------------------------------------------
git add .    ==> No Message.


---------------------------------------------------
git status  ==>
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   .gitignore
        new file:   Cargo.lock
        new file:   Cargo.toml
        new file:   src/main.rs


---------------------------------------------------
git commit -m "Initial commit" ==>
[master (root-commit) dbcc2cf] Initial commit
 4 files changed, 17 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.lock
 create mode 100644 Cargo.toml
 create mode 100644 src/main.rs


---------------------------------------------------
git status ==>
On branch master
nothing to commit, working tree clean


---------------------------------------------------
git branch ==>
* master

---------------------------------------------------
git checkout -b feat/add_new_line ==>
Switched to a new branch 'feat/add_new_line'

---------------------------------------------------
git status ==>
On branch feat/add_new_line
nothing to commit, working tree clean


---------------------------------------------------
Change the code ==>

fn main() {
println!("Hello, world!");
println!("Added new line");
}


---------------------------------------------------
cargo run ==>
   Compiling test_app v0.1.0 (/home/rubenq/rust/test_app)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/test_app`
Hello, world!
Added new line


---------------------------------------------------
git add .  ==> No message


---------------------------------------------------
git status ==>
On branch feat/add_new_line
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   src/main.rs


---------------------------------------------------
git branch ==>
* feat/add_new_line
  master

---------------------------------------------------
git commit -m "feat:  adding new line" ==>
[feat/add_new_line c6bcc97] feat:  adding new line
 1 file changed, 1 insertion(+)


---------------------------------------------------
git branch  ==>
* feat/add_new_line
  master


---------------------------------------------------
This is the code:

fn main() {
println!("Hello, world!");
println!("Add new line");
}


---------------------------------------------------
git checkout master ==>
Switched to branch 'master'


---------------------------------------------------
This is the code:

fn main() {
println!("Hello, world!");

}


There is not error message, but the master branch is not updated.

You committed your change onto the feat/add_new_line branch. This does not modify the master branch, so when you switch to the master branch, your change is not there.

If you want master to contain the same changes as feat/add_new_line, you have to run another command to do that. There are several ways to do that; a simple one is, while on the master branch, run git merge feat/add_new_line. In this simple case, that will just change master to point to the same commit c6bcc97 as feat/add_new_line currently does.

(This merge command is roughly the same thing that merging a pull request on GitHub does.)

2 Likes

Thanks a lot, kpreid.

You are right.

I'll improve my git skills.

Regards.