Memo

メモ > 技術 > 開発: Git > コマンドで作業&コミット&プッシュする

■コマンドで作業&コミット&プッシュする
■作業ブランチを作成 現在のブランチを確認
$ git branch * develop master
作業ブランチとして feature/test を作成
$ git branch feature/test
ブランチを切り替え
$ git checkout feature/test Switched to branch 'feature/test'
ブランチの切り替えを確認
$ git branch develop * feature/test master
■作業内容をコミット 作業内容の差分を確認
$ git status -bs ## feature/test M index.html
作業内容の差分の詳細を確認
$ git diff -- index.html diff --git a/index.html b/index.html index 795b8df..68ba275 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ </head> <body> <h1>Test</h1> - <p>テストページです。</p> + <p>これはテストページです。</p> <ul> <li><a href="page1.html">テストページ1</a></li> <li><a href="page2.html">テストページ2</a></li> $ git status On branch feature/test Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: index.html
作業内容をステージに追加
$ git add index.html
ステージに追加した内容を取り消す場合
$ git checkout HEAD -- index.html
もしくは以下
$ git reset index.html $ git status On branch feature/test Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: index.html $ git status -bs ## feature/test M index.html $ git commit -m "文言を修正" [feature/test 6049160] 文言を修正 1 file changed, 1 insertion(+), 1 deletion(-) $ git log --oneline --graph --decorate -5 * 6049160 (HEAD -> feature/test) 文言を修正 * a920e34 (origin/master, origin/develop, origin/HEAD, master, develop) 文言を修正 * 4a16324 (tag: v1.0, tag: title) Merge branch 'develop' |\ | * c27017c Merge branch 'title' into develop | |\ | | * dbd4095 addressを追加
■作業内容をコミット(参考) ステージに追加したファイルが複数の場合、以下のように表示される
$ git status On branch feature/test Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: page1.html modified: page2.html Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: page3.html $ git status -bs ## feature/test M page1.html M page2.html M page3.html
■作業内容をプッシュ
$ git push origin feature/test … ユーザ名とパスワードを求められる Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 12 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 317 bytes | 317.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 2 local objects. remote: remote: Create a pull request for 'feature/test' on GitHub by visiting: remote: https://github.com/refirio/test/pull/new/feature/test remote: To https://github.com/refirio/test.git * [new branch] feature/test -> feature/test
■作業内容をマージしてプッシュ
$ git checkout develop Switched to branch 'develop' Your branch is up to date with 'origin/develop'. $ git merge feature/test Updating a920e34..6049160 Fast-forward index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) $ git push origin develop Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/refirio/test.git a920e34..6049160 develop -> develop

Advertisement