Open digitallyamar opened 6 years ago
~/alpha $ git add data/letter.txt
~/alpha $ printf '1234' > data/number.txt
alpha └── data └── letter.txt └── number.txt
~/alpha $ git add data
Make a correction and add the file to the index again:
~/alpha $ printf '1' > data/number.txt ~/alpha $ git add data
~/alpha $ git commit -m 'a1' [master (root-commit) c81d2ea] a1
~/alpha $ printf '2' > data/number.txt
This results in working directory containing content different from index or git database. Add new content to index:
~/alpha $ git add data/number.txt
This results in new object blob created. It points the index entry for data/number.txt at the new blob:
~/alpha $ git commit -m 'a2'
~/alpha $ git checkout 0956eb
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD is now at 0956ebb... a2
Update & commit number.txt file content again
~/alpha $ printf '3' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a3' [detached HEAD d13d2e9] a3
This just creates a new file at .git/refs/heads/deputy that contains the hash that HEAD is pointing at: the hash of the a3 commit.
Checkout the master branch again:
~/alpha $ git checkout master Switched to branch 'master'
This puts HEAD back to pointing to master:
~/alpha $ git checkout deputy Switched to branch 'deputy'
~/alpha $ git merge master Already up-to-date.
~/alpha $ git checkout master Switched to branch 'master'
~/alpha $ git merge deputy Fast-forward
~/alpha $ printf '4' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a4' [master e98bf22] a4
Next checkout deputy branch and update content there too!
~/alpha $ git checkout deputy Switched to branch 'deputy' ~/alpha $ printf 'b' > data/letter.txt ~/alpha $ git add data/letter.txt ~/alpha $ git commit -m 'b3' [deputy 98b33e9] b3
Finally merge the two branches:
~/alpha $ git merge master -m 'b4' Merge made by the 'recursive' strategy.
~/alpha $ git checkout master Switched to branch 'master' ~/alpha $ git merge deputy Fast-forward
~/alpha $ git checkout deputy Switched to branch 'deputy' ~/alpha $ printf '5' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'b5' [deputy bd797c2] b5
~/alpha $ git checkout master Switched to branch 'master' ~/alpha $ printf '6' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'b6' [master 4c3ce18] b6
~/alpha $ git merge deputy CONFLICT in data/number.txt Automatic merge failed; fix conflicts and commit the result.
5
deputy
Manually fix the merge conflict. In our case, we simply update the number.txt file with a new value
~/alpha $ printf '11' > data/number.txt ~/alpha $ git add data/number.txt
~/alpha $ git commit -m 'b11' [master 5b7f752] b11
Step 1: Create a Git Repo
~ $ mkdir alpha ~ $ cd alpha
~/alpha $ mkdir data ~/alpha $ printf 'a' > data/letter.txt
~/alpha $ git init Initialized empty Git repository
The alpha directory now looks like this: alpha ├── data | └── letter.txt └── .git ├── objects etc...
This results in a initial git repo that looks like this: